-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f29202e
commit 9444b0e
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const sect = document.querySelector('.quiz'); | ||
const option1 = document.querySelector('.opt1'); | ||
const option2 = document.querySelector('.opt2'); | ||
const option3 = document.querySelector('.opt3'); | ||
const option4 = document.querySelector('.opt4'); | ||
|
||
let timer; | ||
let stopwatch = document.querySelector('.stopwatch'); | ||
let s = 0; | ||
let m = 0; | ||
let formattedTime; | ||
|
||
function startQuizStopwatch() { | ||
timer = setInterval(updateStopwatch, 1000); | ||
} | ||
|
||
function stopStopwatch() { | ||
clearInterval(timer); | ||
} | ||
|
||
function updateStopwatch() { | ||
s++; | ||
|
||
if (s === 60) { | ||
s = 0; | ||
m++; | ||
} | ||
|
||
formattedTime = pad(m) + ':' + pad(s); | ||
stopwatch.innerHTML = formattedTime; | ||
} | ||
|
||
function pad(value) { | ||
return value < 10 ? '0' + value : value; | ||
} | ||
|
||
function shuffle(array) { | ||
let currentIndex = array.length, randomIndex; | ||
while (currentIndex > 0) { | ||
|
||
randomIndex = Math.floor(Math.random() * currentIndex); | ||
currentIndex--; | ||
|
||
[array[currentIndex], array[randomIndex]] = [ | ||
array[randomIndex], array[currentIndex]]; | ||
} | ||
|
||
return array; | ||
} | ||
|
||
function script(subject, topic) { | ||
console.log("Test 1 passed"); | ||
|
||
fetch('/subjects/' + subject + '/' + topic + '.json') | ||
.then(response => response.json()) | ||
.then(data => { | ||
console.log("Test 2 passed"); | ||
|
||
let shuffled = shuffle(data); | ||
|
||
shuffled.forEach(item => { | ||
document.querySelector('.key_term').innerHTML = item.term; | ||
let random_option = Math.floor(Math.random * 4); | ||
if (random_option == 0) { | ||
option1.innerHTML = item.meaning; | ||
} else if (random_option == 1) { | ||
option2.innerHTML = item.meaning; | ||
} else if (random_option == 2) { | ||
option3.innerHTML = item.meaning; | ||
} else { | ||
option4.innerHTML = item.meaning; | ||
} | ||
}); | ||
|
||
|
||
|
||
}); | ||
}) | ||
.catch(error => console.error('Error fetching JSON', error)); | ||
|
||
} |