-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoogle in Colors.js
28 lines (22 loc) · 1.25 KB
/
Google in Colors.js
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
//used in devtools - console. Google Home. A Random color at user clicks
const htmlBody = document.querySelector('body');
//htmlBody = Google home body
//Creating a function
const randomClickFunction = function () {
const colors = ["green", "blue", "yellow", "purple", "black", "grey", "red", "orange", "#ca335c", "#471147"]; //setting Colors variable
const randomIndex = Math.floor(Math.random() * colors.length); // Getting a random array number from colors
const randomColor = colors[randomIndex]; //setting randomcolor to retrieved random color
htmlBody.style.backgroundColor = randomColor; //setting Backgroundcolor of htmlBody
console.log('The user clicked. The color is now ' + randomColor); // Confirmation. Congratulations!
}
//raw to copy:
const randomClickFunction = function () {
const colors = ["green", "blue", "yellow", "purple", "black", "grey", "red", "orange", "#ca335c", "#471147"];
const randomIndex = Math.floor(Math.random() * colors.length);
const randomColor = colors[randomIndex];
htmlBody.style.backgroundColor = randomColor;
console.log('The user clicked. The color is now ' + randomColor);
}
// See if it works: Type randomClickFunction()
//Assign the Fuction to a click
htmlBody.onclick = randomClickFunction;