Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Random Quotes</title>
</head>
<body>
<h1>Random Quotes</h1>
<ul>

</ul>
<button type="submit">Get Random Quote</button>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="script.js"></script>
</body>
</html>
53 changes: 53 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
$(function(){

var myHeader = new Headers({
"X-Mashape-Key": "c4vYgfOINAmshnnJighZi26DLxMcp1NUYY7jsnRkY6RVXbKLHY",
});
// console.log(myHeader);
var myInit = {
method: 'POST',
headers: myHeader
};

var url = "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous&count=10"

var ul = $('ul');
var $button = $('button')

$button.on('click', function(){
fetch(url, myInit)
.then((response) => { //when we get response back
// console.log('response received')
// console.log(response.json())
return response.json()
})
.then(data => {
data.forEach(function (element) {
var quote = element.quote;
var author = element.author;
var $p = $('<p>').text(`Author: ${author}`)
var $li = $('<h3> <li>').text(`Quote: ${quote}`);
ul.append($li, $p)
})
// console.log('data processed and converted into json');
// console.log(data);
})
.catch((err) => {
// console.log('error happened somewhere')
// console.log(err);
})
});













});