Hello everybody,
I’m new here and my name is Hans. For Javascript I have a question about the following code.
"use strict";
const startBtn = document.getElementById("btn-start");
const resetBtn = document.getElementById("btn-reset");
const countDisplay = document.getElementById("time-left");
let timeLeft = 10;
startBtn.addEventListener("click", CountDown);
function CountDown() {
timeLeft = timeLeft - 1;
if (timeLeft <= 0) {
clearTimeout(timeLeft = 0);
}
setTimeout( CountDown, 1000);
countDisplay.innerHTML = timeLeft;
}
resetBtn.addEventListener("click", resetCounter);
function resetCounter() {
let timeZero = 10;
countDisplay.innerHTML = timeZero;
}
It is a counter that works so far. This counts down from 10 to 0. Unfortunately, the reset function (function resetCounter) doesn’t work and I can’t find the error.
Can someone give me a tip here.
Best regards
Hans