How to Random number JavaScript

How to create a function to get a random number.

Math.random

We will use the Math.random function.

Example

Math.random()*3 will return 0, 1 and 2.

var players = Array(); players[0] = "Max"; players[1] = "Ted"; players[2] = "Marshall"; var randomnumber=Math.floor(Math.random()*3) alert(players[randomnumber] + "!");

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*