-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (48 loc) · 1.73 KB
/
script.js
File metadata and controls
55 lines (48 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
let problems = [];
let currentProblemIndex = 0;
function getRandomIntFromArray(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
function generateMultiplicationProblem() {
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const numbers2 = [2, 5, 10];
const num1 = getRandomIntFromArray(numbers);
const num2 = getRandomIntFromArray(numbers);
return {num1, num2, answer: num1 * num2};
}
function generateProblems() {
problems = [];
for (let i = 0; i < 10; i++) {
problems.push(generateMultiplicationProblem());
}
}
function showQuestion() {
if (currentProblemIndex < problems.length) {
const problem = problems[currentProblemIndex];
document.getElementById('question').textContent = `What is ${problem.num1} x ${problem.num2}?`;
currentProblemIndex++;
setTimeout(showQuestion, 6000);
} else {
showResults();
}
}
function showResults() {
const resultsContainer = document.getElementById('results');
resultsContainer.innerHTML = '<h2>Quiz Results:</h2><ol>';
problems.forEach((problem, index) => {
resultsContainer.innerHTML += `<li>${problem.num1} x ${problem.num2} = ${problem.answer}</li>`;
});
resultsContainer.innerHTML += '</ol>';
document.getElementById('question').textContent = 'Quiz completed!';
document.getElementById('startButton').style.display = 'block';
}
function startQuiz() {
generateProblems();
currentProblemIndex = 0;
document.getElementById('startButton').style.display = 'none';
document.getElementById('results').innerHTML = '';
showQuestion();
}
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('startButton').addEventListener('click', startQuiz);
});