Cancel previous timeout
continuous-integration/drone/push Build is passing Details

main
Clément FRÉVILLE 1 year ago
parent b5ec58b936
commit 90400a09ea

@ -8,6 +8,9 @@ const display = /** @type {HTMLDivElement} */ (document.getElementById('display'
const light = /** @type {HTMLDivElement} */ (document.getElementById('light'));
const keypad = /** @type {HTMLDivElement} */ (document.getElementById('keypad'));
/** @type {number|null} */
let taskId = null;
/**
* @param {number} len
* @returns {string}
@ -30,6 +33,10 @@ function resetCode() {
* @param {number} digit
*/
function composeDigit(digit) {
if (taskId !== null) {
clearTimeout(taskId);
taskId = null;
}
builder += digit.toString();
display.innerText = builder + '_'.repeat(CODE.length - builder.length);
light.classList.remove(IS_SUCCESS, IS_ERROR);
@ -37,7 +44,7 @@ function composeDigit(digit) {
light.classList.add(IS_SUCCESS);
} else {
light.classList.add(IS_ERROR);
setTimeout(resetCode, DELAY);
taskId = setTimeout(resetCode, DELAY);
}
}

Loading…
Cancel
Save