forked from LisCoding/Interview-Algo-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorGame.html
41 lines (34 loc) · 1.11 KB
/
colorGame.html
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
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html lang="en">
<head>
<title>Lab 13</title>
<style>
</style>
</head>
<body>
</body>
<script>
myFunction()
function myFunction() {
let red = Math.floor(Math.random()*255);
let green = Math.floor(Math.random()*255);
let blue = Math.floor(Math.random()*255);
let red_hex = red.toString(16);
let green_hex = green.toString(16);
let blue_hex = blue.toString(16);
if (red.length < 10)
red_hex = "0" + red_hex;
if (green.length < 10)
green_hex = "0" + green_hex;
if (blue.length < 10)
blue_hex = "0" + blue_hex;
let hex = "#"+red_hex+green_hex+blue_hex;
document.body.innerHTML = '';
document.write("BACKGROUND-COLOR IS RANDOMLY GENERATED<br><br>");
document.write("RGB(", red, ",", green, ",", blue, ")<br><br>");
document.write("HEX: ", hex, "<br><br>");
document.body.style.backgroundColor = hex;
document.write("<a onclick='myFunction()' style='color:blue; text-decoration:underline;'>CLICK TO RANDOM</a>")
}
</script>
</html>