-
Notifications
You must be signed in to change notification settings - Fork 8
/
quiz.js
39 lines (24 loc) · 1.07 KB
/
quiz.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
let questionDiv = document.querySelector('.question');
let answersDiv = document.querySelector('.answers');
let messageDiv = document.querySelector('.message');
// 1. Fetch the quiz data from the `db.json` file using the `fetch()` function.
// 2. Use a .then method and convert the response to JSON.
// 3. Use a second .then method and grab the data.
// 4. Uncomment the code below and place it in the body of the second .then method.
// questionDiv.innerHTML = data.question;
// for (const answer of data.answers) {
// let answerButton = document.createElement('div');
// answerButton.classList.add('answer');
// answerButton.innerHTML = answer.text;
// answerButton.addEventListener('click', () => {
// if (answer.correct) {
// messageDiv.innerHTML = 'Correct!';
// messageDiv.style.color = "green"
// } else {
// messageDiv.innerHTML = 'Incorrect!';
// messageDiv.style.color = "red"
// }
// });
// answersDiv.appendChild(answerButton);
// }
// 5. Discuss what's happening in the code above.