Practice on timers and working with the DOM in JavaScript
Let us have an input:
html<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:
javascriptlet elem = document.querySelector('#elem');
setInterval(function() {
elem.value = Number(elem.value) + 1;
}, 1000);
Задание 1
Explain why the Number function is used in
the above code. What happens if you don't write
this function in this code?
Задание 2
Let the input in the value attribute initially
contain the number 10. Start a timer that will
decrease this number by one every second.
Задание 3
Modify the previous task so that as soon as the content of the input becomes zero, the timer stops running.