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
23 changes: 23 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chaser</title>
<!-- <link rel="stylesheet" href="style.css"> -->

</head>
<body>
<div class="container">
<h1>Random Quote Generator</h1>

<p></p>

<button id = "new-quote">Generate New Quote</button>

<a id = "tw-button" target="_blank"><button id="twitter"><i class ="fa fa-twitter"></i> Tweet this</button></a>

</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="script.js" charset="utf-8"></script>
</body>
</html>
45 changes: 45 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
$(function () {

var url = 'https://andruxnet-random-famous-quotes.p.mashape.com/'
var quoteText = ""
var quoteAuthor = ""
var headers = new Headers()

headers = {
'X-Mashape-Key': 'B9R2k43o8dmshpgKEIc90NRAPN88p1dJ9wLjsnueovKDDWMdH1'
}

var apiCall = fetch(url, {
method: 'POST',
headers: headers})

console.log('api call')
console.log(apiCall)

// // ------------- start of success function ------------- //

apiCall
.then((response) => { // when we get response back
// console.log('response received')
// console.log(response.json())
return response.json()
})
.then((data) => { //because this is doing the same thing as function writeLiEveryArticle(data)
console.log('data processed and converted to json')
console.log(data)
var $p = $('p')
$p.text(data.quote)
})

// // ------------- end of success function ------------- //

// // ------------- start of fail function ------------- //

.catch((err) => {
console.log('error happened somewhere')
console.log(err)
})

// ------------- end of fail function ------------- //

})