1

I need to have a function drawSomething(x,y,color,boolean) how do I generate random integers so the position of x and y displays somewhere in the canvas, the color could be any of the three, and the boolean could be either true or false? but everything randomly

let colors = ['red','yellow','blue'];

drawSomething(x,y,color,boolean)
  • 3
    Does this answer your question? [Generate random number between two numbers in JavaScript](https://stackoverflow.com/questions/4959975/generate-random-number-between-two-numbers-in-javascript) – ethane Mar 17 '21 at 06:59
  • What is the `boolean` supposed to do? – Sebastian Simon Mar 17 '21 at 07:01
  • [Duplicate](https://google.com/search?q=site%3Astackoverflow.com+js+random+element+of+array) of [Getting a random value from a JavaScript array](https://stackoverflow.com/q/4550505/4642212). – Sebastian Simon Mar 17 '21 at 07:02

1 Answers1

0

Math.floor(Math.random() * 10);

for integers between 0 to 9, you can replace 10 with other numbers to change the range.