-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
21 lines (13 loc) · 918 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const colors =["green","red","white","teal","yellow","whitesmoke","orange","violet","brown","blue","thistle","yellowgreen","darkblue","cyan","darkcyan","darkgoldenrod","magenta","darkmagenta","darkolivegreen","lavender","indigo","darkslategray","maroon","aqua","indianred","salmon","crimson","pink","lightpink","cadetblue","cornsilk","wheat","tan","sandybrown","sienna","azure","mintcream","aliceblue","honeydew","royalblue","navy","silver"];
const btn = document.getElementById("btn");
const color = document.getElementById("color");
btn.addEventListener("click",function(){
//get random number between 0-3
const randomNumber = getRandomNumber();
console.log(randomNumber);
document.body.style.backgroundColor = colors[randomNumber];
color.textContent = colors[randomNumber];
});
function getRandomNumber(){
return Math.floor(Math.random() * colors.length);
}