Lab8 - Random Testimonial TroubleShooting
Link to Lab8
This lab seems very simple, but it was hard coming up with a way to make it possible. In this lab, we were assigned that task of making a quote on a webpage change everytime the page is reloaded. To make this happened, I used the set of quotes given to us and make it into an array. Then set up a function that would create a random number within the number range of the array length. Then make it so that only the quote with the random number generate would appear. The code is found below:
This lab seems very simple, but it was hard coming up with a way to make it possible. In this lab, we were assigned that task of making a quote on a webpage change everytime the page is reloaded. To make this happened, I used the set of quotes given to us and make it into an array. Then set up a function that would create a random number within the number range of the array length. Then make it so that only the quote with the random number generate would appear. The code is found below:
var quotes = [
"These days sleeping at your desk is not just acceptable, it's encouraged. — The Atlantic",
"NAPS has changed the way people think about sleep, on a grand scale. — Washington Post ",
"Happiness increased 200% since NAPS began promoting siestas. — National Science Review ",
"NAPS has ushered in a new era of sleep. — USA Today ",
"Not surprisingly, more siestas means more productivity. — Wall Street Journal ",
"NAPS is doing the hard work of helping people get the rest they need. — U.S. News ",
"NAPS is by far the most significant cultural force of the decade. — New York Times ",
];
var randomNum = Math.floor(Math.random()*quotes.length);
document.getElementById('press-quote').innerHTML= quotes[randomNum];
No code involved had to do anything with reloading the page, it is just that everytime the page is loaded a new number would be generated; therefore, a new quote would appear.

Comments
Post a Comment