Ask coding questions

← Back to all posts
how do you show your cps in html
RyanCheung1 (3)

I am trying to complete a money clicker game, the last thing I need to complete is a cps tracker to show the clicks per second. pls give me the code to be able to do this

Comments
hotnewtop
InvisibleOne (2986)
<h4>Clicks Per Second: <span id='clickPerSec'></span><h4>

in the JS

cps = 1;
document.getElementById('clickPerSec').innerHTML = cps;

setInterval(function(){
  clicks += cps;
}, 1000) // this function will run once every second. 
RyanCheung1 (3)

@InvisibleOne even though this works, it doesn't show the cps counter

InvisibleOne (2986)

wdym? Do you want it to display how many clicks per second you have, or did you want something else? @RyanCheung1

InvisibleOne (2986)

You mean update the score each time? add this inside of thesetInterval function.

document.getElementById('moneyValue').innerHTML = clicks;
// do the same for the lifetime Money

@RyanCheung1

RyanCheung1 (3)

@InvisibleOne I want to display how many clicks per second I have

RyanCheung1 (3)

@InvisibleOne it doesn't update the clicks per second