-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path100-projects-014-sample-quiz2.js
More file actions
71 lines (66 loc) · 2.52 KB
/
100-projects-014-sample-quiz2.js
File metadata and controls
71 lines (66 loc) · 2.52 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let questions = [
{
question: 'What is the capital of France?',
options: ['Paris', 'Berlin', 'London', 'Madrid'],
correctAnswer: 'Paris'
},
{
question: 'Who is the current president of the USA?',
options: ['Barack Obama', 'Donald Trump', 'Joe Biden', 'Hillary Clinton'],
correctAnswer: 'Joe Biden'
},
{
question: 'What is the process by which plants make their own food called?',
options: ["Cellular Respiration", 'Digestion', 'Photosynthesis', 'Osmosis'],
correctAnswer: 'Photosynthesis'
},
{
question: 'What is the smallest unit of life in all living organisms called?',
options: ['Cell', 'Molecule', 'Organ', 'Tissue'],
correctAnswer: 'Cell'
},
{
question: 'What is the force that pulls objects towards each other called?',
options: ['Friction', 'Magnetic Force', 'Electric Force', 'Gravity'],
correctAnswer: 'Gravity'
},
{
question: 'What are the building blocks of protein?',
options: ['Nucleotides', 'Amino Acids', 'Fatty acids', 'Glucose'],
correctAnswer: 'Amino Acids'
},
{
question: 'What are the four largest planets in our solar system?',
options: ['Earth, Mars, Venus, Mercury', 'Mars, Jupiter, Saturn, Venus', 'Mercury, Venus, Earth, Mars', 'Jupiter, Saturn, Uranus, Neptune'],
correctAnswer: 'Jupiter, Saturn, Uranus, Neptune'
},
/*can add more questions following structure*/
];
let currentQuestion = 0;
function loadQuestion() {
let questionContainer = document.getElementById('question');
let optionContainer = document.getElementById('option-container');
questionContainer.textContent = questions[currentQuestion].question;
optionContainer.innerHTML = '';
for (let i = 0; i < questions[currentQuestion].options.length; i++) {
let option = document.createElement('div');
option.className = 'option';
option.textContent = questions[currentQuestion].options[i];
option.addEventListener('click', function () {
if (option.textContent === questions[currentQuestion].correctAnswer) {
option.style.backgroundColor = 'lightgreen';
} else {
option.style.backgroundColor = 'salmon';
}
});
optionContainer.appendChild(option);
}
}
function loadNextQuestion() {
currentQuestion++;
if(currentQuestion < questions.length) {
loadQuestion();
} else {
alert('Quiz Finished!');
}
}