I’m trying to do the random quote generator, but we didn’t learn how to create a JSON file. I created an array holding 20 sub-arrays, each with a quote and its author, but I think it’s supposed to be an object.(?) Can someone just post a small example of a JSON file of strings, something that the code would work with.
$.getJSON("quotes.json", function(json) {
$(".quotebox").html(JSON.stringify(json));
});
json.forEach(function(value){
var keys = Object.keys(value);
html += "<div class="quote");
keys.forEach(function(key) {
html += "<strong>" + key + "</strong>": + value[key] + "<br />";
});
html += "</div> <br />"; });
//Generates a random number, 0 - 255.
$("#newQuote").click(function() {
var myQuote = Math.floor(Math.random() * 20);
// User can click to get a new quote.
$("#newQuote").on("click", function() {
$(".quote").html("Your quote: ");
}