I'm trying to build this chrome extention that alerts you once the timer is done and it should be automatic. However I'm keep getting the errors
Uncaught ReferenceError: timer is not defined
Uncaught TypeError: Cannot set properties of null (setting 'innerHTML')
var startingMinutes = 30;
let time = startingMinutes * 60;
setInterval(function () {
const timer = document.getElementById('timer');
const minutes = Math.floor(time / 60);
let seconds = time % 60;
seconds = seconds < 10 ? '0' + seconds : seconds;
timer.innerHTML = `${minutes}:${seconds}`;
time--;
time = time < 0 ? 0 : time;
if (time == 0) {
fn();
time = startingMinutes * 60;
return;
}
function fn() {
alert("!")
}
}, 1000);