Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
(I've posted the same exact question but with Little information, I am posting another one as I couldn't find the option to edit my question)
I've seen tutorials on click counter that adds a number whenever you click a button, but all of them start at 0, what I'm asking is a click counter that can start at maybe .000, or .000000 something like that. I've tried to improvise as many times as I could, Ive reread tutorials on JavaScript, but I just can't do it.
Again, simplifying what I want...
A button, that when click will increase the value of a given number (eg.0.00) by a given number (eg.0.001)
Eg
No click
0.00
One click
0.01
Two click
0.02
Three click
0.03

What I have tried:

JavaScript
<h3><center>JavaScript Click Counter</center></h3>
<div>
    <center><h3 id="counter-label">0</h3></center>
</div>
<center>
    <div>
        Click Me
        Reset
    </div>
</center>

var counterVal = 0.00;

function incrementClick() {
    updateDisplay(++counterVal);
}

function resetCounter() {
    counterVal = 0.00;
    updateDisplay(counterVal);
}

function updateDisplay(val) {
    document.getElementById("counter-label").innerHTML = val;
}
Posted
Updated 16-Jan-22 0:26am
v3
Comments
Patrice T 16-Jan-22 4:43am    
Use Improve question to update your question.

1 solution

Quote:
I couldn't find the option to edit my question

Use Improve question to update your question.
Quote:
I've seen tutorials on click counter that adds a number whenever you click a button, but all of them start at 0, what I'm asking is a click counter that can start at maybe .000, or .000000 something like that.

All those are the same starting point 0 written in z different way.
What you are looking for is a different increment
JavaScript
updateDisplay(++counterVal); // here the increment is 1

counterVal += 1;             // here the increment is 1
updateDisplay(counterVal);

counterVal += 0.01;          // here the increment is 0.01
updateDisplay(counterVal);

counterVal += 0.0001;        // here the increment is 0.0001
updateDisplay(counterVal);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900