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
21 changes: 21 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title></title>
</head>

<body>
<section id="quotes"><h2>Quotes<h2></section>
<section id="other">Other stuff</section>
<input id="input1" type="text">



<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- <script src="script2.js" charset="utf-8"></script> -->
<script src="script.js" charset="utf-8"></script>
</body>

</html>
34 changes: 34 additions & 0 deletions ref.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 1257
Content-Type: application/json
Date: Mon, 09 Oct 2017 08:16:43 GMT
Server: Mashape/5.0.6


[
{
"quote": "Go ahead, make my day.",
"author": "Sudden Impact",
"category": "Movies"
},
{
"quote": "All right, Mr. DeMille, I'm ready for my close-up.",
"author": "Sunset Blvd.",
"category": "Movies"
},
{
"quote": "Show me the money!",
"author": "Jerry Maguire",
"category": "Movies"
},
{
"quote": "If you build it, he will come.",
"author": "Field of Dreams",
"category": "Movies"
},
{
"quote": "I see dead people.",
"author": "The Sixth Sense",
"category": "Movies"
},
47 changes: 47 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
$(function() {
var url = 'https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies&count=3'
var myHeaders = new Headers({
'X-Mashape-Key': 'GhlVH0tapJmshXdUM8M5oCgL2vG0p1nFlhrjsnuUkb3fyGMux9',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
});
//fix this.
var myInit = {
method: 'POST',
headers: myHeaders
}
var apiCall = fetch(url, myInit)

apiCall
.then((response) => {
// console.log(response.json()) //also async
return response.json()
})
.then(writeJoke)
.catch((err) => {
console.log(err);
})

function writeJoke(jokes) {
var $quotes = $('#quotes')
var $body = $('body')
var $newULList = $('<ul>')

jokes.forEach(joke => {
var $newListItem = $('<li class="article title">')
var $newP = $('<h3>')
var $newAuth = $('<p>')
$newP.text(`"${joke.quote}"`)
$newAuth.text('by ' + joke.author)
$newListItem.append($newP, $newAuth)
$newULList.append($newListItem)
})
// $body.append($newULList)
$quotes.append($newULList)
// console.log(joke);
// console.log(joke.quote);
// console.log(joke.author);
// console.log(joke.category);
}

});
54 changes: 54 additions & 0 deletions script2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
$(function() {
// var $input = $('#input1')
// var song = $input.val
// var song = "hello"
// console.log(song);
var url = 'https://instatunes.p.mashape.com/search'
var myHeaders = new Headers({
'X-Mashape-Key': 'GhlVH0tapJmshXdUM8M5oCgL2vG0p1nFlhrjsnuUkb3fyGMux9',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
"title":"hello",
});
var myInit = {
method: 'POST',
headers: myHeaders
}
var apiCall = fetch(url, myInit)

apiCall
.then((response) => {
// console.log(response.json()) //also async
return response.json()
})
.then(showSong)
.catch((err) => {
console.log(err);
})

function showSong(song) {
console.log(song);
var $quotes = $('#other')
// var $body = $('body')
// var $newULList = $('<ul>')

// songs.forEach(song => {
// var $newListItem = $('<li>')
var $link = $('<a>')
var $newP = $('<h3>')
// var $newAuth = $('<p>')
$link.attr('href', song.stream_link)
$newP.text(song.title)
// $newAuth.text('by ' + joke.author)
// $newListItem.append($newP, $link)
// $newULList.append($newListItem)
// })
// $body.append($newULList)
$quotes.append($newP, $link)
// console.log(joke);
// console.log(joke.quote);
// console.log(joke.author);
// console.log(joke.category);
}

});