Reputation: 61
I'd like to program A page with a single button, when i press it, one of the pages (from a list in Javascript code) should be randomly opened. How do I do it? Thanks a lot!
Upvotes: 0
Views: 158
Reputation: 1075079
Well, let's see. There's
Math.random()
, which will give you a random number between 0
(inclusive) and 1
(exclusive)
window.location
, a property to which you can assign a URL to take the browser to a new page
Arrays, which can contain strings, which can be URLs
Put them together, and you have the ability to pick a URL at random (from the array, using Math.random
) and tell the browser to go there.
Upvotes: 5