160k views
0 votes
Can someone create a code in JAVASCRIPT that makes the colors change randomly in a circle. Build on or change my setTimer function.

Can someone create a code in JAVASCRIPT that makes the colors change randomly in a-example-1
User John Lord
by
8.6k points

1 Answer

7 votes

Answer:

Step-by-step explanation:

html

head

script

var colors = ["red", "green", "blue", "#ff00ff", "orange", "yellow"];

function changeColor() {

var getRandomColor = colors[Math.floor(Math.random() * colors.length)];

document.getElementById("circle").style.background = getRandomColor;

};

setInterval(changeColor, 1000); //every one second

document.getElementById("rectangle").style.backgroundColor = "brown";

/script

/head

body

<div id="rectangle" id="circle">"></div>

<div id="circle"></div>

/body

/html

User Kekolab
by
7.6k points