Hello Friends, help me please!!!
Now I try will do simple, without random, $.ajax give me qutes from json, but cant put to the #aut and #quo in the html, where i did error?
{
"quotes": [
{ "quote":"Life isn’t about getting and having, it’s about giving and being.","author":"Kevin Kruse"},
{ "quote":"Whatever the mind of man can conceive and believe, it can achieve.","author":"Napoleon Hill"}
]
}
<p id="aut">Must be author</p>
<p id="quo">Must be quote</p>
<button id="get">But</button>
let jsonQuotes;
let currentAuth = "";
let currentQuote = "";
function getQuotes(){
$.ajax({
url: 'https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json',
success: function(data){
jsonQuotes = JSON.parse(data);
// alert(jsonQuotes.quotes[0].quote)
}
});
}
function getRandomQuote(){
return jsonQuotes.quotes[0];//here i get object
}
function getQuote(){
let randomQuote = getRandomQuote();
currentAuth = randomQuote.author;
currentQuote = randomQuote.quote;
$('#aut').html(randomQuote.author);
$('#quo').html(randomQuote.quote);
}
$(document).ready(function() {
getQuotes().then(() => {
getQuote();
});
$('#get').on('click', getQuote);
});
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/front-end-libraries-projects/build-a-random-quote-machine/