-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomColor.html
More file actions
41 lines (36 loc) · 1.12 KB
/
Copy pathrandomColor.html
File metadata and controls
41 lines (36 loc) · 1.12 KB
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>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Random Color</title>
<style>
* {
text-align: center;
user-select: none;
}
</style>
</head>
<body>
<h1 id="random-color-h1">Get Random Color</h1>
<br />
<button id="random-color-Btn">Get Random Color</button>
<!-- Script i.e javascript Source -->
<script>
//select all elements by ID
const randomColorH1 = document.getElementById("random-color-h1");
const randomColorBtn = document.getElementById("random-color-Btn");
let generateRandomColor = async () => {
let apiUrl = await fetch("https://x-colors.yurace.pro/api/random");
let result = await apiUrl.json();
//Apply Random color on H1 tag
randomColorH1.style.color = result.rgb;
//Apply Random color on button
randomColorBtn.style.color = result.rgb;
// console.log(result);
};
setInterval(generateRandomColor, 500);
generateRandomColor();
</script>
</body>
</html>