Skip to content
Sign upLog in
← Back to Community

How To Click A Button And Adds 1 TO A NUmber

Profile icon
ArivMukati

in HTML CSS and JS im trying to print a number and add 1 to that number

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
mahithaprasad
Profile icon
GeumjuKim
Profile icon
ArivMukati
Comments
hotnewtop
Profile icon
Coder100

Sure! Try something like:

<div id="number">0</div> <button id="click">Click me</button>
let clicks = 0; document.getElementById("click").addEventListener("click", () => { clicks++; document.getElementById("number").innerHTML = clicks; })

working repl

Profile icon
ArivMukati

thanks!

Profile icon
ArivMukati

What language 9is this

Profile icon
ArivMukati

oh wait i know its html

Profile icon
Coder100

np! Mark as correct answer?

@ArivMukati

Profile icon
ArivMukati

an error just says that cannot read add whever whever

Profile icon
Coder100

@ArivMukati
wait what send repl

Profile icon
ArivMukati

helllo

Profile icon
ArivMukati

its saying TypeError: Cannot read property 'addEventListener' of null
at /script.js:2:33

Profile icon
ArivMukati