-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
25 lines (22 loc) · 1.04 KB
/
script.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
let lampRandom = document.getElementById('lampRandom');
let lampRed = document.getElementById('lampRed');
let lampGreen = document.getElementById('lampGreen');
let lampBlue = document.getElementById('lampBlue');
lampRandom.addEventListener('click', () => {
let color = Math.floor(Math.random() * 360); // random number between 0 and 360
let saturation = Math.floor(Math.random() * 100); // random number between 0 and 100
let lightness = Math.floor(Math.random() * 100); // random number between 0 and 100
let colorString = `hsl(${color}, ${saturation}%, ${lightness}%)`;
let Body = document.querySelector('body'); // select the body element (kuno)
Body.style.background = colorString;
console.log(colorString);
})
lampRed.addEventListener('click', () => {
document.body.style.background = 'crimson'; // langsung ganti warna background
})
lampGreen.addEventListener('click', () => {
document.body.style.background = 'lightgreen';
})
lampBlue.addEventListener('click', () => {
document.body.style.background = 'lightblue';
})