-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.js
More file actions
128 lines (109 loc) · 4.04 KB
/
2.js
File metadata and controls
128 lines (109 loc) · 4.04 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
const options = document.querySelectorAll('.option');
const audioCorrect = document.getElementById('audioCorrect');
const audioIncorrect = document.getElementById('audioIncorrect');
const audio = document.getElementById('qa2');
document.getElementById('lifeline3').onclick = function(){
const lifeline3Used = sessionStorage.getItem('lifeline3_used');
if (lifeline1Used) {
alert("Lifeline 3 has already been used in Previous Question!");
} else {
document.getElementById('ans').innerHTML = "Answer is: B";
sessionStorage.setItem('lifeline3_used', true);
this.disabled = true;
}
};
document.getElementById('lifeline2').onclick = function(){
const lifeline2Used = sessionStorage.getItem('lifeline2_used');
if (lifeline2Used) {
alert("Lifeline 2 has already been used in Previous Question!");
} else {
document.getElementById('lifeline2').onclick = function(){
window.location.href = 'https://www.google.com';
};
sessionStorage.setItem('lifeline2_used', true);
this.disabled = true;
}
};
document.getElementById('lifeline1').onclick = function(){
const lifeline1Used = sessionStorage.getItem('lifeline1_used');
if (lifeline1Used) {
alert("Lifeline 1 has already been used in Previous Question!");
} else {
const element = document.getElementById('op4');
if (element.style.color === 'transparent') {
element.style.color = ''; // Reset to default color
} else {
element.style.color = 'transparent';
}
const element1 = document.getElementById('op3');
if (element1.style.color === 'transparent') {
element1.style.color = ''; // Reset to default color
} else {
element1.style.color = 'transparent';
}
sessionStorage.setItem('lifeline1_used', true);
this.disabled = true;
}
};
// Flag to track if the audio is playing
let audioPlaying = false;
// Play audio when page loads
window.onload = function () {
audio.play();
audio.onended = function () {
audioPlaying = false;
// Enable options after audio ends
options.forEach(function (opt) {
opt.disabled = false;
});
};
};
function redirectToNextPage() {
setTimeout(function () {
window.location.href = "3.html"; // Replace "next_page.html" with the URL of your next page
}, 4000); // 4 seconds delay
}
function redirectToLostPage() {
setTimeout(function () {
window.location.href = "1000.html"; // Replace "next_page.html" with the URL of your next page
}, 3000); // 4 seconds delay
}
// Add click event listener to each option
options.forEach(option => {
option.addEventListener('click', () => {
// Check if the audio is still playing
if (audioPlaying) {
return; // Do nothing if audio is playing
}
// Remove selected class from all options
options.forEach(opt => opt.classList.remove('selected'));
// Add selected class to the clicked option
option.classList.add('selected');
// Get the selected answer
const selectedAnswer = option.getAttribute('data-answer');
// Check if the selected answer is correct
if (selectedAnswer === 'B') {
audioCorrect.play();
option.classList.add('correct');
redirectToNextPage();
} else {
audioIncorrect.play();
redirectToLostPage();
option.classList.add('incorrect');
}
// Disable other options
options.forEach(function (opt) {
if (opt !== option) {
opt.disabled = true;
}
});
});
});
// Event listener for audio play
audio.addEventListener('play', function () {
audioPlaying = true;
});
// Event listener for audio pause
audio.addEventListener('pause', function () {
audioPlaying = false;
});