I posted my work online here:
Instructions on how to reproduce:
- Click on a green pin on the map to select a station
- Fill in the fields for name and last name
Sign on the canvas
A timer should start counting down from 20 minutes
- If you click on the "cancel" button, the timer should be reset
- If you then resign on the canvas, the timer should restart from 20 minutes
The timer functionality is located in the file /js/timer.js.
I am facing an issue where even though I use clearInterval(this.setTimer)
and sessionStorage.clear()
in my cancel function, the timer is not resetting properly. Debugging shows that this.setTimer
increases by 1 every time I cancel, although it should be resetting to 10.
Am I missing something? The desired behavior is for the timer to reset to 20 minutes when the "cancel" button is clicked.
Below is my cancel function:
cancel = () => {
this.isPlaying = false;
clearInterval(this.setTimer);
sessionStorage.clear();
console.log(this.setTimer);
canvas.clear();
this.timer.innerHTML = 'Your reservation has been canceled.'
document.getElementById('reservation-content').classList.remove('hidden');
document.getElementById('cancel-btn').className = 'hidden';
document.getElementById('validation-btn').setAttribute('disabled', null)
}