I am learning JS and found nice projekt, simple random quote by button press. Unfortunately some AJAX was used. I tried to rebuild it in JS only and failed.
Are there some useful websites which help in "translating" languages (AJAX->JS)? Could you look over my code and give me some feedback? Original:
https://codepen.io/miomate/pen/wRzPaQ
My changes:
function randomize(){
var range = data.notes.length;
var random_index = Math.floor(Math.random() * range);
var item = data.notes[random_index];
document.getElementByClassName("quote-content").innerHTML = item.quote;
document.getElementByClassName("quote-book").innerHTML = item.title;
document.getElementByClassName("quote-author").innerHTML = item.author;
}
document.getElementsByClassName("next").onlick = getQuote();
function getQuote(){
randomize();
};
document.addEventListener("DOMContentLoaded", function(event) {
randomize();
getQuote();
});
Thank you very much.
Aucun commentaire:
Enregistrer un commentaire