Let us have an input:
<input id="elem" value="1">
Let's make a timer that every second increments the
value of the value
attribute of our
input by one:
let elem = document.querySelector('#elem');
setInterval(function() {
elem.value = Number(elem.value) + 1;
}, 1000);
Explain why the Number
function is used in
the above code. What happens if you don't write
this function in this code?
Let the input in the value
attribute initially
contain the number 10
. Start a timer that will
decrease this number by one every second.
Modify the previous task so that as soon as the content of the input becomes zero, the timer stops running.