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
20 changes: 20 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Random Quote Generator</title>
</head>
<body>
<h1>Random Quote Generator</h1>

<h2></h2>

<button type="button" name="button">Press Me!</button>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src ="script.js" type="text/javascript">

</script>
</body>
</html>
39 changes: 39 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
$(function(){

//console.log(requestApi)
//Now use it!
$('button').on('click',randomQuotes)

function randomQuotes(){
var requestApi = fetch('https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies&count=1',
{method: 'POST',
headers: new Headers({
'X-Mashape-Key': 'akWsSBApPNmshKDzi6hnIxnTnhpCp1QDDbijsnG63ow6St7aWJ',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
})
})
requestApi
.then((response) => { //when we got response bacl
console.log('response received');
// console.log(response.json())
return response.json()
})
.then(writeLiEveryArticle)
.catch((err) => { //if fail run this part
console.log('error happened somewhere');
console.log(err)
/* handle response */
})
}


function writeLiEveryArticle(data) {
console.log(data);
var $h2 = $('h2')
$h2.text(data.quote)

}


})