1

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.

  • 4
    Duplicate: [How to print a number with commas as thousands separators in JavaScript](https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript) –  Apr 20 '21 at 21:33
  • Skip the accepted answer on that dupe and use [this answer](https://stackoverflow.com/a/17663871/215552). – Heretic Monkey Apr 20 '21 at 21:34
  • Woah, that's a lot confusing for me. I know it's easy for your guys, because you know about JavaScript. But I don't know so much, that's confusing. Looking at the answers I see the output is with commas and not dot, so It would not answer my question. Also, I think it would not help me during the increase of the numbers, maybe I'm wrong, but OK. If possible, just answer me, please, I don't want to be stuck in more complicated things. –  Apr 20 '21 at 21:42

0 Answers0