+ 1

How to write JavaScript with HTML?

I am making my first JS game which will be a simple square, and when you touch it you get a point and you only have so much time.... This is my code... How come the points don’t go up when I touch it?? https://code.sololearn.com/WWHzMDy7uydC/?ref=app

23rd Jun 2018, 4:05 AM
Kyle
Kyle - avatar
3 Respostas
+ 4
try adding <span id="counter"></span> to your html, then in your function add document.getElementById("counter").innerText = count; also calling the function inline JavaScript should be onclick="hi()"
23rd Jun 2018, 5:24 AM
MCJEH
MCJEH - avatar
+ 1
You have only 'written' the value - once - to the node, not updating it. In order to do so, the update has to be included in the click() function to count the value everytime you click. Also, document.write() will keep previous values on display, I would suggest you use .innerHTML for better visual.
23rd Jun 2018, 4:20 AM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar
0
i still dont understand
23rd Jun 2018, 4:57 AM
Kyle
Kyle - avatar