1. Open the project with visual studio

  2. Go to /Views/StudentExam/TakeExam.cshtml

  3. Scroll down until you see the “function startTimer”, change it to the code below.

    function startTimer(duration) {
        var timerid = "totalSecondsLeft" + "@Model.StudentId" + "@Model.ExamId";
        let durationInSecond = duration * 60;
        if (localStorage.getItem(timerid) == null) {
            localStorage.setItem(timerid, durationInSecond);
        }
        let totalSecondsLeft = localStorage.getItem(timerid) || durationInSecond;
        interval = setInterval(() => {
            let totalSecondsLeft = localStorage.getItem(timerid);
            totalSecondsLeft--;
            localStorage.setItem(timerid, totalSecondsLeft);
            const hours = Math.floor(totalSecondsLeft / 3600);
            const minutes = Math.floor((totalSecondsLeft % 3600) / 60);
            const seconds = totalSecondsLeft % 60;
            let timer = document.getElementById("timer");
            timer.innerHTML = hours + ':' + minutes.toString().padStart(2, '0') + ':' + seconds.toString().padStart(2, '0');
            if (totalSecondsLeft === 0) {
                clearInterval(interval);
                localStorage.removeItem(timerid);
                timer.innerHTML = "Time is up!";
                window.location.href = "@Url.Action("timesup", "studentexam")" + "?eId=" + "@Model.ExamId" + "&sId=" + "@Model.StudentId";
                return;
            }
        }, 1000);
    }
    
  4. Done! Now try to test with a new exam.