Simple counter in Javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Counter</title>
<link href="style.css" rel="stylesheet">
</head>
<body>
<div class ="counter" style="font-size: xx-large; margin-top: 200px;" >
Counter <br>
<span class = "count"> 0 </span>
</div>
<button class = "addbtn" id = "addmybtn" style="font-size: xx-large; margin-top: 50px; text-align:center" >Add </button>
<button class = "addbtn" id = "reset" style="font-size: xx-large; margin-top: 50px; text-align:center" >Reset </button>
<button class = "decreasebtn" id = "decreasebtn" style="font-size: xx-large; margin-top: 50px; text-align:center" >Decrease </button>
<script src="counter.js"></script>
</body>
</html>
Script.js
const btn = document.querySelector("#addmybtn");
const display = document.querySelector(".count");
console.log(display)
let value = 0;
btn.addEventListener("click", function ()
{
value += 1;
display.textContent = value;
});
decreasebtn.addEventListener("click", function ()
{
value -= 1;
display.textContent = value;
});
reset.addEventListener("click", function ()
{
value = 0;
display.textContent = value;
});