0
How do run my code in JavaScript such that it makes a random choice from some given choices after the code is executed?
I want the code to make a choice between some choices given randomly. How I can do it in JavaScript?
3 Respuestas
+ 3
var options = ['1st choice', '2nd choice', '3rd choice'];
finalChoice = options[Math.floor(Math.random()*options.length)]
https://code.sololearn.com/WNRBMpU2H6t0/?ref=app
+ 1
Well, I want the output to be a number which is randomly chosen from the given few inputs.
- 2
Can you explain better what are you trying to accomplish
- You make a function that create a random number whit Math. Random and set the desire chooses to that random number in the arra of options