()
| 2 | |
| 3 | |
| 4 | function 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 | |
| 42 | function resetNumbers(currentNos, nextNos, end) { |
nothing calls this directly
no test coverage detected