Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Jeremy Coleman5,449 Points
Phrase or Quote on Refresh?
I know what I want, not sure how to code it or what to look for. Basically, I want for example 10 phrases or quotes but only 1 of those 10 will randomly appear on the website. It changes upon refresh.
Bonus to this would to add a button just the phrase refreshes and not the entire website. Can anyone point me in the right direction for this? Thank you!
Three hits for this. Do not want to give you to much.
1.You are going to need a randoms number. (Math.random()) 2.Some way to store the quotes in your code and a way to get them with a number. 3.And a function combining those two elements and to call the function when the button gets pressed.
Let me know if you want more hints but see what you can come up with.
Jason Desiderio21,811 Points
Jeremy Coleman - Here is a video lesson describing pretty much what you are looking for. It chooses a random word (which you can change to phrases) from an array and displays it on the page when the button is pressed. You'll be able to modify it to run on page load as well as on the button click event.
Hope this helps!