-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquiz.js
More file actions
128 lines (114 loc) · 3.9 KB
/
Copy pathquiz.js
File metadata and controls
128 lines (114 loc) · 3.9 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var quizData = [
{
image: 'images/quiz/welcome.jpg',
correctAnswer: 'Welcome',
choices: ['Freedom', 'Inspect', 'Welcome', 'Surround']
},
{
image: 'images/quiz/come.jpg',
correctAnswer: 'Come',
choices: ['Bear', 'Come', 'Kite', 'Tree']
},
{
image: 'images/quiz/language.jpg',
correctAnswer: 'Language',
choices: ['Language', 'Pattern', 'Highway', 'Balloon']
},
{
image: 'images/quiz/save.jpg',
correctAnswer: 'Save',
choices: ['Fish', 'Save', 'Joke', 'Luck']
},
{
image: 'images/quiz/hello.jpg',
correctAnswer: 'Hello',
choices: ['Candy', 'Lemon', 'Hello', 'Chess']
},
{
image: 'images/quiz/help.jpg',
correctAnswer: 'Help',
choices: ['Moon', 'Help', 'Walk', 'Love']
},
{
image: 'images/quiz/learning.jpg',
correctAnswer: 'Learning',
choices: ['Favorite', 'Festival', 'Audience', 'Learning']
},
{
image: 'images/quiz/phone.jpg',
correctAnswer: 'Phone',
choices: ['Phone', 'Dance', 'Apple', 'Plant']
},
{
image: 'images/quiz/Which language.jpg',
correctAnswer: 'BSL',
choices: ['ASL', 'CSL', 'FSL', 'BSL']
},
{
image: 'images/quiz/freedom.jpg',
correctAnswer: 'Freedom',
choices: ['Perfect', 'Freedom', 'Shelter', 'Society']
},
];
var currentQuestionIndex = 0;
var score = 0;
var incorrect = false;
document.getElementById('score-image').src = 'images/score-based-image/l.png';
function displayQuestion() {
var question = quizData[currentQuestionIndex];
document.getElementById('question-image').src = question.image;
var choiceButtons = document.getElementsByClassName('choice-button');
for (var i = 0; i < choiceButtons.length; i++) {
choiceButtons[i].textContent = question.choices[i];
choiceButtons[i].onclick = function() {
checkAnswer(this.textContent);
};
}
}
function updateImageBasedOnScore() {
var imageElement = document.getElementById('score-image'); // Assuming you have an image with id 'score-image'
if (score <= 2) {
imageElement.src = 'images/score-based-image/l.png'; // Low score image
} else if (score <= 6) {
imageElement.src = 'images/score-based-image/m.png'; // Medium score image
} else {
imageElement.src = 'images/score-based-image/h.png'; // High score image
}
}
function checkAnswer(userChoice) {
var question = quizData[currentQuestionIndex];
if (userChoice === question.correctAnswer) {
score++;
document.getElementById('result').textContent = 'Correct!';
updateImageBasedOnScore(); // Call the function here if the answer is correct
} else {
incorrect = true;
document.getElementById('result').textContent = 'Incorrect. The correct answer was ' + question.correctAnswer;
document.getElementById('play-again').style.display = 'block';
document.querySelector('h3').textContent = 'You Made him Sad';
document.getElementById('score-image').src = 'images/score-based-image/l.png';
}
// Rest of the code...
currentQuestionIndex++;
if (currentQuestionIndex < quizData.length && !incorrect) {
displayQuestion();
} else {
document.getElementById('play-again').style.display = 'block';
if (incorrect) {
document.getElementById('result').textContent = 'Quiz complete! Your score is ' + score;
} else {
document.getElementById('result').textContent = 'Congratulations! You have completed the quiz with a perfect score!';
}
}
document.getElementById('score').textContent = 'Score: ' + score;
}
document.getElementById('play-again').addEventListener('click', function() {
location.reload(); // This will refresh the page
});
document.getElementById('start').addEventListener('click', function() {
this.style.display = 'none';
document.querySelector('h3').textContent = ''; // Make the "Play to Make him Happy" disappear
if (currentQuestionIndex === 0) { // Only display the question if it's the first question
displayQuestion();
}
});