-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject3.html
51 lines (46 loc) · 1.32 KB
/
project3.html
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
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Counter</title>
</head>
<style>
#Counter{
display: inline;
justify-content: center;
background-color: #414141;
}
</style>
<body>
<div class="box">
<div id="Counter">
<h2 id="count">Count is 0</h2>
</div>
<div id="buttonAll">
<button class = "button" id="sub">Dercrease</button>
<button class = "button" id="add">Increase</button>
<button class = "button" id="reset">Reset</button>
</div>
</div>
</body>
<script>
const button = document.querySelectorAll(".button");
const count = document.querySelector("#count");
var number = 0;
button.forEach((button) => {
button.addEventListener("click",(e)=>{
// console.log("ayush");
if(e.target.id === "add"){
count.innerHTML = `<h2>Count is ${++number}</h2>`
}
else if (e.target.id === "sub") {
count.innerHTML = `<h2>Count is ${--number}</h2>`
}else{
number = 0;
count.innerHTML = `<h2>Count is ${number}</h2>`
}
})
});
</script>
</html>