I'm trying to make a counter in JavaScript, problem is that I'm stuck, because it seems difficult for me.
The thing is: I want to be able to add a dot when the counter reach 1.000
The output:
$ 1000,00
Expected result:
$ 1.000,00
Code:
var increase = document.querySelector("#myId");
function increment() {
var current = increase.textContent;
if (current != 2500) {
increase.textContent = parseInt(current) + 1 + "," + "00";
setTimeout(increment, 10);
}
}
increment()
body {
font-family: Arial;
font-size: 30pt;
}
<p>$ <span id="myId">500</span></p>
You need to run the JavaScript code in the console.
I don't have any idea to put a dot .
when the counter reaches 1k+
Thanks,
I highly appreciate your help.