-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflipper.js
More file actions
29 lines (27 loc) · 714 Bytes
/
flipper.js
File metadata and controls
29 lines (27 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const colors = [
"red",
"blue",
"green",
"yellow",
"purple",
"orange",
"pink",
"cyan",
"lime",
"violet"
]
//event listeners
const label = document.getElementById("colorlabel");
const button = document.getElementById("flipbutton");
// function to pick random colors
function flipcolor(){
// pick a random position from the array
const randomindex = Math.floor(Math.random() * colors.length);
// get the value at that position
const color = colors[randomindex];
// change background
document.body.style.backgroundColor = color;
// change text label
label.textContent = "Current color: " + color;
}
button.addEventListener("click", flipcolor);