0
Wats wrong with this Javascript code
const decreaser = document.getElementById('decreaser'); const reset = document.getElementById('reset'); const increase = document.getElementById('increase'); let counter = 0; increase.addEventListener("click", function (){ counter += 1; number.innerHTML = counter; }); reset.addEventListener("click", function(){ counter +=0; number.innerHTML = counter; }); decreaser.addEventListener ("click", function(){ counter -= 1; number.innerHTML = counter; });
4 Answers
+ 3
Please link your complete code:
Click +, Insert Code, sort for My Code Bits, select your code
+ 3
You are not created any IDs but searching for those. and 'number' is unknown in number.innerHTML
Share link by saving it.
Add ids to buttons. & create number division.
+ 3
Delete all lines with constants.
Instead of:
number.innerHTML = counter;
Write:
document.display.innerHTML = counter;
0
<!DOCTYPE html>
<html>
<head>
<title>counter</title>
</head>
<body>
<div class="container">
<h1>Counter</h1>
<display>5</display>
<button onclick="decreaser()"> Decrease </button>
<button onclick="reset()"> Reset </button>
<button onclick="increase()"> Increase </button>
</div>
</body>
</html>