<aside> 💡 When the user clicks, start the countdown from 10 to 0 for the 1st pose picture
</aside>
setInterval()
can be a bit funky in the global window object. So I've used 3 separate functions for each of the
<h1 id='timerText'class="text-center my-5"></h1>
let count1 = 10;
function countdown1() {
document.getElementById('snap').disabled = true
var timer1 = setInterval(function() {
if (count1 < 0) {
clearInterval(timer1);
document.getElementById('timerText').innerHTML = 'Next Pose';
func()
} else {
document.getElementById('timerText').innerHTML = count1
console.log(count1);
count1--
}
}, 1000)
}
countdown1()
references the function for the first countdown from 10 to 0 for the first pose picture<button>
because we don't want the countdown to be interrupted once started
setInterval()
method to variable timer1
this is because we will use the clearInterval()
method and pass in timer1
which references the setInterval()
function as an argumentSetInterval():
variable = setInterval(function, milliseconds);
if
conditional checks if variable count1 is less than 0. If true, then use the clearInterval()
method that takes timer1
as an argument, which references the setInterval()
function. We also want to let the user that the countdown is over so we add the string "Next Pose" to the innerHTML property of the DOM element with id of 'timerText'. And lastly since the countdown is over we called function picture1()
which will click a picture of the current pose.