count button click in javascript code example
Example 1: javascript counting when clicking a button
var myButton = document.getElementById("my-button");
var myOutput = document.getElementById("my-output");
var startNumber = 0;
function addToNumber(){
myOutput.innerHTML = `The current number is: ${1+startNumber++}`;
}
myButton.onclick = addToNumber;
Example 2: javascript count number of clicks limit
let count = 0;
count++;
console.log(count);
if (count>6){
document.getElementById("btn").disabled = true;
alert("Game over!!!");
}