-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
119 lines (101 loc) · 3.58 KB
/
script.js
File metadata and controls
119 lines (101 loc) · 3.58 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
document.addEventListener('DOMContentLoaded', () => {
const pieceElements = document.querySelectorAll('.piece1');
const pieceImage = document.getElementById('piece-image1');
pieceElements.forEach(piece => {
piece.addEventListener('click', () => {
const imageSrc = piece.getAttribute('data-image');
pieceImage.src = imageSrc;
});
});
});
document.getElementById("redirectButton1").addEventListener("click", function() {
window.location.href = "https://youtu.be/AaKWUiiEHgA";
});
document.getElementById("redirectButton2").addEventListener("click", function() {
window.location.href = "https://youtu.be/Z-2FpiEzeYI";
});
document.getElementById("redirectButton3").addEventListener("click", function() {
window.location.href = "https://youtu.be/tsDJLUL-vo4";
});
document.getElementById("redirectButton4").addEventListener("click", function() {
window.location.href = "https://youtu.be/mX_fQyxKiPQ";
});
document.addEventListener('DOMContentLoaded', () => {
const pieceElements = document.querySelectorAll('.piece2');
const pieceImage = document.getElementById('piece-image2');
pieceElements.forEach(piece => {
piece.addEventListener('click', () => {
const imageSrc = piece.getAttribute('data-image');
pieceImage.src = imageSrc;
});
});
});
const quizData = [
{
question: "How many squares are there on a standard chessboard?",
options: ["64", "72", "56", "60"],
answer: "64"
},
{
question: "Which piece can move in an L-shape?",
options: ["Pawn", "Knight", "Rook", "Bishop"],
answer: "Knight"
},
{
question: "What is the ultimate goal in chess?",
options: ["Capture the opponent's queen", "Checkmate the opponent's king", "Promote a pawn", "Stalemate the opponent"],
answer: "Checkmate the opponent's king"
}
];
let currentQuestion = 0;
let score = 0;
const quiz = document.getElementById("quiz");
const questionElement = document.getElementById("question");
const optionsElement = document.getElementById("options");
const resultElement = document.getElementById("result");
const nextButton = document.getElementById("next-btn");
function loadQuestion() {
const currentQuizData = quizData[currentQuestion];
questionElement.innerText = currentQuizData.question;
optionsElement.innerHTML = "";
currentQuizData.options.forEach(option => {
const button = document.createElement("button");
button.innerText = option;
button.classList.add("option-btn");
button.addEventListener("click", selectOption);
optionsElement.appendChild(button);
});
nextButton.style.display = "none";
}
function selectOption(e) {
const selectedOption = e.target.innerText;
const currentQuizData = quizData[currentQuestion];
if (selectedOption === currentQuizData.answer) {
score++;
}
const optionButtons = document.querySelectorAll(".option-btn");
optionButtons.forEach(button => {
button.disabled = true;
if (button.innerText === currentQuizData.answer) {
button.classList.add("correct");
} else {
button.classList.add("incorrect");
}
});
nextButton.style.display = "block";
}
function nextQuestion() {
currentQuestion++;
if (currentQuestion < quizData.length) {
loadQuestion();
} else {
showResult();
}
}
function showResult() {
quiz.style.display = "none";
resultElement.innerHTML = `<h2>Quiz Completed!</h2><p>Your Score: ${score} out of ${quizData.length}</p>`;
resultElement.style.display = "block";
}
nextButton.addEventListener("click", nextQuestion);
loadQuestion();