I create a random quote machine that will present a random quote from various philosophers.
I have an object literal with nested objects containing philosophers and their quotes. Using jQuery and Math.random () functions, how can I select a random quote from my object literal structure? Is there a better way to organize the data?
I started by closing jQuery, which will display the assigned quote, which I would like to change using Math.random ().
Looking for an explanation of the solutions as I am new. Thanks in advance.
Example object literal:
var quotes =
{
awatts: {
name: "Alan Watts",
quote: "The only way to make sense out of change is to plunge into it, move with it, and join the dance."
},
etolle: {
name: "Eckhart Tolle",
quote: "Realize deeply that the present moment is all you ever have."
},
tmckenna: {
name: "Terrence Mckenna",
quote: ""The cost of sanity in this society, is a certain level of alienation" "
}
};
Examples of jQuery functions with a single quotation mark selected:
$(document).ready(function() {
$('.mybutton').click(function() {
$('#quote').html(quotes.awatts.quote);
});
});