-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.js
63 lines (51 loc) · 1.53 KB
/
tasks.js
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
56
57
58
59
60
61
62
63
const taskContainer = document.getElementById("task");
const taskQuestions = [
{
question: "What does the 'X' axis in the CIE XYZ color space represent?",
},
{
question:
"What is the range of values possible for each coordinate (X, Y, and Z) in the CIE XYZ space?",
},
];
let currentTaskQuestion = 0;
function displayQuestion() {
const questionData = taskQuestions[currentTaskQuestion];
const html = `
<div class="task">
<div class="question">${questionData.question}</div>
<input type="text" id="answerInput">
<div>
<button class="btn" id="submitBtn">Submit</button></div>
</div>
`;
taskContainer.innerHTML = html;
const submitButton = document.getElementById("submitBtn");
submitButton.addEventListener("click", handleSubmission);
}
function handleSubmission() {
const answerInput = document.getElementById("answerInput").value;
taskQuestions[currentTaskQuestion].answer = answerInput;
currentTaskQuestion++;
if (currentTaskQuestion < taskQuestions.length) {
displayQuestion();
} else {
showResult();
}
}
function showResult() {
const resultHtml = `
<div id="result">Answers submitted!</div>
<button class="btn" id="restartBtn">Restart Quiz</button>
`;
taskContainer.innerHTML = resultHtml;
const restartButton = document.getElementById("restartBtn");
restartButton.addEventListener("click", () => {
currentTaskQuestion = 0;
taskQuestions.forEach((question) => {
question.answer = "";
});
displayQuestion();
});
}
displayQuestion();