0

I am trying to randomize the values in an array.

Is it acceptable to type out my code like this:

var buttonColours = ["red", "blue", "green", "yellow"];
var randomChosenColour = Math.random(buttonColours.length);
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
  • 4
    Does this answer your question? [Get a random item from a JavaScript array](https://stackoverflow.com/questions/5915096/get-a-random-item-from-a-javascript-array) – kunquan Jan 06 '21 at 09:49
  • 1
    Does this answer your question? [How to randomize (shuffle) a JavaScript array?](https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array) – Reza Rahimi Jan 06 '21 at 10:39

1 Answers1

0

No.
random() return number between 0-1.
use Math.floor(Math.random() * buttonColours.length)

ATP
  • 2,939
  • 4
  • 13
  • 34