Skip to content

Commit db764f7

Browse files
committed
Color Changer
1 parent 49b1553 commit db764f7

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

Projects/01-Color-Changer/index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Color Changer</title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
<body>
10+
<div class="canvas">
11+
<div class="heading">
12+
<h1>Project 1: Color Changer</h1>
13+
<h3>Try clicking on one of the colors below to change the background color of this page!</h3>
14+
</div>
15+
16+
<span class="btn" id="grey"></span>
17+
<span class="btn" id="white"></span>
18+
<span class="btn" id="blue"></span>
19+
<span class="btn" id="yellow"></span>
20+
</div>
21+
<script src="script.js"></script>
22+
</body>
23+
</html>

Projects/01-Color-Changer/script.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Select Color and canvas
2+
const buttons = document.querySelectorAll('.btn');
3+
const canvas = document.querySelector('.canvas');
4+
5+
buttons.forEach((button) => {
6+
console.log(button);
7+
button.addEventListener('click', (e) => {
8+
9+
const validColor = ['grey', 'white', 'blue', 'yellow'];
10+
const color = e.target.id;
11+
12+
if(validColor.includes(color)){
13+
canvas.style.backgroundColor = color
14+
}
15+
16+
17+
// if (e.target.id === 'grey') {
18+
// canvas.style.backgroundColor = e.target.id;
19+
// }
20+
// else if (e.target.id === 'white') {
21+
// canvas.style.backgroundColor = e.target.id;
22+
// }
23+
// else if (e.target.id === 'blue') {
24+
// canvas.style.backgroundColor = e.target.id;
25+
// }
26+
// else if (e.target.id === 'yellow') {
27+
// canvas.style.backgroundColor = e.target.id;
28+
// }
29+
});
30+
})
31+
32+
33+
// Apply color to canvas

Projects/01-Color-Changer/style.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
* {
2+
font-family: monospace;
3+
margin: 0;
4+
}
5+
6+
span {
7+
display: block;
8+
}
9+
10+
.canvas {
11+
text-align: center;
12+
height: 100vh;
13+
}
14+
15+
.heading h1, .heading h3 {
16+
margin-bottom: 20px;
17+
}
18+
19+
.btn {
20+
width: 100px;
21+
height: 100px;
22+
border: solid black 2px;
23+
display: inline-block;
24+
cursor: pointer;
25+
}
26+
27+
#grey {
28+
background: grey;
29+
}
30+
31+
#white {
32+
background: white;
33+
}
34+
35+
#blue {
36+
background: blue;
37+
}
38+
39+
#yellow {
40+
background: yellow;
41+
}
42+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy