-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRGB.html
More file actions
21 lines (21 loc) · 683 Bytes
/
RGB.html
File metadata and controls
21 lines (21 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RGB BG</title>
</head>
<body>
<h1>Press a key to change the background color ( R G B W)</h1>
<script>
document.addEventListener('keydown', (event) => {
const key = event.key.toLowerCase();
if (['r', 'g', 'b'].includes(key)) {
document.body.style.backgroundColor = key === 'r' ? 'red' : key === 'g' ? 'green' : 'blue';
} else if (key === 'w') {
document.body.style.backgroundColor = 'white';
}
});
</script>
</body>
</html>