Skip to content

Commit 3ee45a7

Browse files
color-changing-app
1 parent b1eb2b6 commit 3ee45a7

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# javascript-color-change-app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//Select 7 colors
2+
let colors = [ 'red', 'blue', 'green', 'orange', 'purple', 'black', 'yellow'];
3+
4+
5+
6+
//change the background of canvas when button is clicked
7+
let button = document.getElementById('button');
8+
9+
button.addEventListener('click', function(){
10+
//select a random number between 0 - 6
11+
let index = parseInt((Math.random()*colors.length)+1);
12+
//grab the canvas
13+
let canvas = document.getElementById('canvas');
14+
15+
canvas.style.background = `${colors[index]}`
16+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<link rel="stylesheet" href="style.css">
8+
<title>JavaScript Color Changing App</title>
9+
</head>
10+
<body>
11+
<div id="canvas">
12+
My background color will change when my button below is clicked.
13+
</div>
14+
15+
<button id="button">Click me!</button>
16+
17+
18+
19+
<script src="app.js"></script>
20+
</body>
21+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#canvas{
2+
background-color: red;
3+
color: white;
4+
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
5+
font-size: 25px;
6+
width: 600px;
7+
height: 500px;
8+
margin: 50px auto 50px;
9+
text-align: center;
10+
display: flex;
11+
justify-content: center;
12+
align-items: center;
13+
}
14+
15+
#button{
16+
text-align: center;
17+
width: 200px;
18+
height: 50px;
19+
margin: 50px auto 50px;
20+
color: white;
21+
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
22+
background: black;
23+
border-radius: 5px;
24+
border-style: none;
25+
display: block;
26+
}

0 commit comments

Comments
 (0)