-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
33 lines (25 loc) · 1.11 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
document.addEventListener("DOMContentLoaded", function() {
const peopleElement = document.getElementById("peopleCount");
const boughtElement = document.getElementById("boughtCount");
let peopleCount = parseInt(localStorage.getItem("savedPeopleCount")) || 0;
let boughtCount = parseInt(localStorage.getItem("savedBoughtCount")) || 0;
let peopleInterval, boughtInterval;
function updateCounter() {
clearInterval(peopleInterval);
clearInterval(boughtInterval);
peopleInterval = setInterval(() => {
peopleCount++;
peopleElement.innerText = formatNumberWithCommas(peopleCount);
localStorage.setItem("savedPeopleCount", peopleCount);
}, 3000);
boughtInterval = setInterval(() => {
boughtCount++;
boughtElement.innerText = formatNumberWithCommas(boughtCount);
localStorage.setItem("savedBoughtCount", boughtCount);
}, 11000);
}
function formatNumberWithCommas(number) {
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
updateCounter();
});