Home › Forums › JavaScript › Get random word from prompt imput › Re: Get random word from prompt imput
March 2, 2013 at 9:24 am
#126677
tomrogers123
Member
You could switch the text to be outputted using a `switch` statement with a random number generation as the condition to switch:
var numRand = Math.floor(Math.random()*2) // generate number between 1 and 3
switch(numRand) {
case 0:
// code for 1st scenario
break;
case 1:
// code for 2nd scenario
break;
case 2:
// code for 3rd scenario
break;
default:
// what to do if, for some reason, an invalid number was parsed
break;
}