-1

I'm creating a game in buildbox, and i'm trying to create a script that is written in javascript(I am not a javascript coder) to choose randomly from a range of colors, for example:

color_list = [color1,color2,color3]

So that it in this list it picks color2 randomly taking into account color 2 is: (255,0,0) in RGB

Thanks for the help!

David Meléndez
  • 389
  • 5
  • 15
  • 1
    Possible duplicate of [Getting a random value from a JavaScript array](https://stackoverflow.com/questions/4550505/getting-a-random-value-from-a-javascript-array) – SuperStormer Nov 04 '18 at 20:52

1 Answers1

1

You could do:

let randomColor = color_list[Math.floor(Math.random() * color_list.length)];

As mentioned in Getting a random value from a JavaScript array

Enes T.
  • 137
  • 2
  • 12