Skip to content

Commit

Permalink
Update quiz.js
Browse files Browse the repository at this point in the history
  • Loading branch information
RasperRevision authored Feb 11, 2024
1 parent af02066 commit 52379bf
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ const option4 = document.querySelector('.opt4');

const section = document.querySelector('.quiz');

let timer;
let stopwatch = document.querySelector('.stopwatch');
let s = 0;
let m = 0;
let formattedTime;
let qtimer;
let qstopwatch = document.querySelector('.quiz_stopwatch');
let qs = 0;
let qm = 0;
let qFormattedTime;

function startQuizStopwatch() {
timer = setInterval(updateStopwatch, 1000);
qtimer = setInterval(updateStopwatch, 1000);
}

function stopStopwatch() {
clearInterval(timer);
clearInterval(qtimer);
}

function updateStopwatch() {
s++;
qs++;

if (s === 60) {
s = 0;
m++;
if (qs === 60) {
qs = 0;
qm++;
}

formattedTime = pad(m) + ':' + pad(s);
stopwatch.innerHTML = formattedTime;
qFormattedTime = pad(qm) + ':' + pad(qs);
stopwatch.innerHTML = qFormattedTime;
}

function pad(value) {
Expand Down Expand Up @@ -74,5 +74,4 @@ function quiz(subject, topic) {
});
})
.catch(error => console.error('Error fetching JSON', error));

}

0 comments on commit 52379bf

Please sign in to comment.