MCPcopy Create free account
hub / github.com/codemistic/Web-Development / startCounter

Function startCounter

Five Digit Up Counter/script.js:4–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2
3
4function startCounter() {
5
6 var number = parseInt(document.getElementById("number").value);
7
8 if(isNaN(number)) {
9 alert("Please enter a number");
10 clearInterval(countInterval); // This is important for the condition when a counter is running and you entered a wrong input for a new counter
11 return;
12 }
13 if(number < 1 || number > 99999) {
14 alert("Range out of bounds");
15 clearInterval(countInterval);
16 return;
17 }
18
19 var currentNos = document.querySelectorAll(".counter .current");
20 var nextNos = document.querySelectorAll(".counter .next");
21 var count = 0;
22
23 // If user clicks on 'Start Counter' button again - remove this function and below line if you don't consider this situation
24 resetNumbers(currentNos, nextNos, 5);
25
26 // Clears the previous interval that was running
27 clearInterval(countInterval);
28
29 countInterval = setInterval(function() {
30 if(count === number) {
31 clearInterval(countInterval);
32 alert("Counter has stopped");
33 return;
34 }
35 increaseCount(currentNos, nextNos, 4);
36 count++;
37 }, 1000);
38
39}
40
41
42function resetNumbers(currentNos, nextNos, end) {

Callers

nothing calls this directly

Calls 2

resetNumbersFunction · 0.70
increaseCountFunction · 0.70

Tested by

no test coverage detected