0

I'm trying to build a counter where if I click a button, it would count up in increments of 10 and have an animation of it counting up by 1. This counter works but when you get up to thousands, there's no comma separator in the number. How would I go about adding this?

Also for a nice to have, how would I save the most recent number locally so that when I refresh, it will still keep that most recent number?

Here is the code I have:

$('#reviewed').click(function() {
  setTimeout(function() {
    $('#dollaramount').html(function(i, val) {
      return val * 1 + 1
    });
  }, 50);

  setTimeout(function() {
    $('#dollaramount').html(function(i, val) {
      return val * 1 + 1
    });
  }, 100);

  setTimeout(function() {
    $('#dollaramount').html(function(i, val) {
      return val * 1 + 1
    });
  }, 150);

  setTimeout(function() {
    $('#dollaramount').html(function(i, val) {
      return val * 1 + 1
    });
  }, 200);

  setTimeout(function() {
    $('#dollaramount').html(function(i, val) {
      return val * 1 + 1
    });
  }, 250);

  setTimeout(function() {
    $('#dollaramount').html(function(i, val) {
      return val * 1 + 1
    });
  }, 300);

  setTimeout(function() {
    $('#dollaramount').html(function(i, val) {
      return val * 1 + 1
    });
  }, 350);

  setTimeout(function() {
    $('#dollaramount').html(function(i, val) {
      return val * 1 + 1
    });
  }, 400);

  setTimeout(function() {
    $('#dollaramount').html(function(i, val) {
      return val * 1 + 1
    });
  }, 450);

  setTimeout(function() {
    $('#dollaramount').html(function(i, val) {
      return val * 1 + 1
    });
  }, 500);
});
Kirk Beard
  • 8,890
  • 12
  • 43
  • 46
Atung9801
  • 13
  • 1
  • 4

0 Answers0