Update index.html
Browse files- index.html +323 -296
index.html
CHANGED
@@ -1,318 +1,345 @@
|
|
1 |
-
|
2 |
<html lang="en">
|
3 |
<head>
|
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 |
-
min-height: 100px;
|
39 |
-
padding: 10px;
|
40 |
-
display: flex;
|
41 |
-
flex-direction: column;
|
42 |
-
align-items: center;
|
43 |
-
justify-content: center;
|
44 |
-
transition: background 0.3s, border-color 0.3s;
|
45 |
-
}
|
46 |
|
47 |
-
|
48 |
-
background: #c8e6c9;
|
49 |
-
border-color: #388e3c;
|
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 |
-
cursor: pointer;
|
101 |
-
background-color: #00796b;
|
102 |
-
color: #fff;
|
103 |
-
border: none;
|
104 |
-
border-radius: 4px;
|
105 |
-
transition: background-color 0.3s;
|
106 |
-
}
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
114 |
|
115 |
-
|
116 |
-
<div id="timer">Time Left: <span id="time">120</span>s</div>
|
117 |
-
|
118 |
-
<div id="game-container"></div>
|
119 |
-
|
120 |
-
<div id="items-container">
|
121 |
-
<!-- Draggable items will be dynamically added here -->
|
122 |
-
</div>
|
123 |
-
|
124 |
-
<div id="feedback"></div>
|
125 |
-
<div id="scoreboard">Score: <span id="score">0</span>%</div>
|
126 |
-
|
127 |
-
<button id="restart-btn" class="hidden" onclick="restartGame()">Restart Game</button>
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
name: "Level 1: Basic Hierarchy",
|
137 |
-
description: "Arrange the hierarchy from Management Groups to Resources.",
|
138 |
-
hierarchy: [
|
139 |
-
{ name: "Management Groups", order: 1, hint: "Top-level structure for organizing policies" },
|
140 |
-
{ name: "Subscriptions", order: 2, hint: "Billing units with associated resource limits" },
|
141 |
-
{ name: "Resource Groups", order: 3, hint: "Organizes resources into manageable units" },
|
142 |
-
{ name: "Resources", order: 4, hint: "Actual Azure services like VMs and databases" }
|
143 |
-
]
|
144 |
-
},
|
145 |
-
{
|
146 |
-
name: "Level 2: Policies and Budgets",
|
147 |
-
description: "Place policies and budgets at the appropriate levels.",
|
148 |
-
hierarchy: [
|
149 |
-
{ name: "Security Policy", order: 1, hint: "Must be applied at the Management Group level" },
|
150 |
-
{ name: "Budget", order: 2, hint: "Assigned to Subscriptions for cost control" },
|
151 |
-
{ name: "Resource Groups", order: 3, hint: "Organizes resources into manageable units" },
|
152 |
-
{ name: "Resources", order: 4, hint: "Actual Azure services like VMs and databases" }
|
153 |
-
]
|
154 |
-
},
|
155 |
-
{
|
156 |
-
name: "Level 3: Azure Resources",
|
157 |
-
description: "Assign specific resources to the correct groups.",
|
158 |
-
hierarchy: [
|
159 |
-
{ name: "Virtual Machines", order: 3, hint: "Placed under Resource Groups" },
|
160 |
-
{ name: "SQL Databases", order: 3, hint: "Placed under Resource Groups" },
|
161 |
-
{ name: "Budget", order: 2, hint: "Assigned to Subscriptions for cost control" },
|
162 |
-
{ name: "Security Policy", order: 1, hint: "Applied at the Management Group level" }
|
163 |
-
]
|
164 |
-
}
|
165 |
-
];
|
166 |
-
|
167 |
-
let currentLevel = 0;
|
168 |
-
let correctCount = 0;
|
169 |
-
let totalItems = 0;
|
170 |
-
let timeLeft = 120; // seconds
|
171 |
-
let timerInterval;
|
172 |
-
|
173 |
-
const gameContainer = document.getElementById("game-container");
|
174 |
-
const itemsContainer = document.getElementById("items-container");
|
175 |
-
const feedbackDiv = document.getElementById("feedback");
|
176 |
-
const scoreSpan = document.getElementById("score");
|
177 |
-
const timerSpan = document.getElementById("time");
|
178 |
-
const restartBtn = document.getElementById("restart-btn");
|
179 |
-
|
180 |
-
function initGame() {
|
181 |
-
totalItems = levels.reduce((sum, level) => sum + level.hierarchy.length, 0);
|
182 |
-
startTimer();
|
183 |
-
loadLevel();
|
184 |
-
}
|
185 |
-
|
186 |
-
function loadLevel() {
|
187 |
-
const level = levels[currentLevel];
|
188 |
-
|
189 |
-
feedbackDiv.textContent = "";
|
190 |
-
gameContainer.innerHTML = "";
|
191 |
-
itemsContainer.innerHTML = "";
|
192 |
-
|
193 |
-
document.querySelector("h1").textContent = level.name;
|
194 |
-
feedbackDiv.textContent = level.description;
|
195 |
-
|
196 |
-
// Create drop zones in order
|
197 |
-
level.hierarchy.forEach(item => {
|
198 |
-
const dropZone = document.createElement("div");
|
199 |
-
dropZone.classList.add("drop-zone");
|
200 |
-
dropZone.id = `drop-zone-${item.order}`;
|
201 |
-
dropZone.setAttribute("ondragover", "allowDrop(event)");
|
202 |
-
dropZone.setAttribute("ondrop", `dropItem(event, 'drop-zone-${item.order}')`);
|
203 |
-
dropZone.innerHTML = `<div class="drop-zone-header">${item.name}</div>`;
|
204 |
-
gameContainer.appendChild(dropZone);
|
205 |
-
});
|
206 |
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
draggable.setAttribute("draggable", "true");
|
213 |
-
draggable.setAttribute("data-order", item.order);
|
214 |
-
draggable.setAttribute("data-attempted", "false"); // Track if item has been attempted
|
215 |
-
draggable.textContent = item.hint;
|
216 |
-
draggable.addEventListener("dragstart", dragStart);
|
217 |
-
itemsContainer.appendChild(draggable);
|
218 |
-
});
|
219 |
-
}
|
220 |
-
|
221 |
-
function shuffleArray(array) {
|
222 |
-
for (let i = array.length - 1; i > 0; i--) {
|
223 |
-
const j = Math.floor(Math.random() * (i + 1));
|
224 |
-
[array[i], array[j]] = [array[j], array[i]];
|
225 |
-
}
|
226 |
-
return array;
|
227 |
-
}
|
228 |
-
|
229 |
-
function allowDrop(event) {
|
230 |
-
event.preventDefault();
|
231 |
-
}
|
232 |
-
|
233 |
-
function dragStart(event) {
|
234 |
-
event.dataTransfer.setData("text/plain", event.target.getAttribute("data-order"));
|
235 |
-
event.dataTransfer.setData("attempted", event.target.getAttribute("data-attempted"));
|
236 |
-
}
|
237 |
-
|
238 |
-
function dropItem(event, zoneId) {
|
239 |
-
event.preventDefault();
|
240 |
-
|
241 |
-
const draggedOrder = parseInt(event.dataTransfer.getData("text/plain"));
|
242 |
-
const attempted = event.dataTransfer.getData("attempted") === "true";
|
243 |
-
const zoneNumber = parseInt(zoneId.replace("drop-zone-", ""));
|
244 |
-
|
245 |
-
const draggedElement = Array.from(itemsContainer.children).find(
|
246 |
-
(child) => parseInt(child.getAttribute("data-order")) === draggedOrder
|
247 |
-
);
|
248 |
-
|
249 |
-
if (draggedOrder === zoneNumber) {
|
250 |
-
event.currentTarget.appendChild(draggedElement);
|
251 |
-
event.currentTarget.classList.add("correct");
|
252 |
-
if (!attempted) {
|
253 |
-
correctCount++;
|
254 |
}
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
timeLeft--;
|
272 |
-
timerSpan.textContent = timeLeft;
|
273 |
-
if (timeLeft <= 0) {
|
274 |
-
clearInterval(timerInterval);
|
275 |
-
endGame(false);
|
276 |
}
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
|
|
293 |
}
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
const percentage = ((correctCount / totalItems) * 100).toFixed(2);
|
300 |
-
if (won && percentage >= 70) {
|
301 |
-
feedbackDiv.textContent = `Congratulations! You've completed all levels with a score of ${percentage}%.`;
|
302 |
-
} else {
|
303 |
-
feedbackDiv.textContent = `Try again! Your score was ${percentage}%.`;
|
304 |
-
}
|
305 |
-
restartBtn.classList.remove("hidden");
|
306 |
-
}
|
307 |
-
|
308 |
-
function restartGame() {
|
309 |
-
currentLevel = 0;
|
310 |
-
correctCount = 0;
|
311 |
-
timeLeft = 120;
|
312 |
-
initGame();
|
313 |
-
}
|
314 |
-
|
315 |
-
window.onload = initGame;
|
316 |
-
</script>
|
317 |
</body>
|
318 |
</html>
|
|
|
1 |
+
\<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Puzzle Quiz Game</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: Arial, sans-serif;
|
10 |
+
text-align: center;
|
11 |
+
background-color: #f4f4f9;
|
12 |
+
padding: 20px;
|
13 |
+
}
|
14 |
+
.puzzle-container {
|
15 |
+
position: relative;
|
16 |
+
width: 400px;
|
17 |
+
height: 300px;
|
18 |
+
margin: 0 auto;
|
19 |
+
}
|
20 |
+
.puzzle {
|
21 |
+
position: absolute;
|
22 |
+
top: 0;
|
23 |
+
left: 0;
|
24 |
+
width: 100%;
|
25 |
+
height: 100%;
|
26 |
+
display: grid;
|
27 |
+
grid-template-columns: repeat(4, 1fr);
|
28 |
+
grid-template-rows: repeat(3, 1fr);
|
29 |
+
gap: 2px;
|
30 |
+
}
|
31 |
+
.piece {
|
32 |
+
background-color: #444;
|
33 |
+
border: 1px solid #333;
|
34 |
+
cursor: pointer;
|
35 |
+
}
|
36 |
+
.piece.hidden {
|
37 |
+
visibility: hidden;
|
38 |
+
}
|
39 |
+
.background-image {
|
40 |
+
position: absolute;
|
41 |
+
top: 0;
|
42 |
+
left: 0;
|
43 |
+
width: 100%;
|
44 |
+
height: 100%;
|
45 |
+
background-image: url('kesslerimage.jpg');
|
46 |
+
background-size: cover;
|
47 |
+
z-index: -1;
|
48 |
+
}
|
49 |
+
#question {
|
50 |
+
margin-top: 20px;
|
51 |
+
font-size: 18px;
|
52 |
+
}
|
53 |
+
.answers {
|
54 |
+
margin-top: 10px;
|
55 |
+
}
|
56 |
+
.answer {
|
57 |
+
margin: 5px;
|
58 |
+
padding: 10px 20px;
|
59 |
+
border: none;
|
60 |
+
cursor: pointer;
|
61 |
+
background-color: #007BFF;
|
62 |
+
color: white;
|
63 |
+
font-size: 16px;
|
64 |
+
border-radius: 5px;
|
65 |
+
}
|
66 |
+
.answer:hover {
|
67 |
+
background-color: #0056b3;
|
68 |
+
}
|
69 |
+
#result {
|
70 |
+
margin-top: 15px;
|
71 |
+
font-size: 20px;
|
72 |
+
}
|
73 |
+
#timer {
|
74 |
+
font-size: 18px;
|
75 |
+
margin-top: 10px;
|
76 |
+
}
|
77 |
+
</style>
|
78 |
+
</head>
|
79 |
+
<body>
|
80 |
+
<h1>Puzzle Quiz Game</h1>
|
81 |
+
<p>Answer questions to remove pieces and reveal the hidden image!</p>
|
82 |
|
83 |
+
<div class="puzzle-container">
|
84 |
+
<div class="background-image"></div>
|
85 |
+
<div class="puzzle" id="puzzle-board">
|
86 |
+
<!-- Puzzle pieces -->
|
87 |
+
<div class="piece" id="piece-1"></div>
|
88 |
+
<div class="piece" id="piece-2"></div>
|
89 |
+
<div class="piece" id="piece-3"></div>
|
90 |
+
<div class="piece" id="piece-4"></div>
|
91 |
+
<div class="piece" id="piece-5"></div>
|
92 |
+
<div class="piece" id="piece-6"></div>
|
93 |
+
<div class="piece" id="piece-7"></div>
|
94 |
+
<div class="piece" id="piece-8"></div>
|
95 |
+
<div class="piece" id="piece-9"></div>
|
96 |
+
<div class="piece" id="piece-10"></div>
|
97 |
+
<div class="piece" id="piece-11"></div>
|
98 |
+
<div class="piece" id="piece-12"></div>
|
99 |
+
</div>
|
100 |
+
</div>
|
101 |
|
102 |
+
<div id="timer">Time Remaining: 120 seconds</div>
|
103 |
+
<div id="question">Click on the start button to begin!</div>
|
104 |
+
<div class="answers" id="answers">
|
105 |
+
<button class="answer" id="start-btn">Start</button>
|
106 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
+
<div id="result"></div>
|
|
|
|
|
|
|
109 |
|
110 |
+
<script>
|
111 |
+
const questions = [
|
112 |
+
{
|
113 |
+
question: "What is a key benefit of Azure ExpressRoute?",
|
114 |
+
answers: [
|
115 |
+
"Faster speeds and higher security",
|
116 |
+
"Free data storage",
|
117 |
+
"Unlimited users",
|
118 |
+
"Global internet access"
|
119 |
+
],
|
120 |
+
correct: 0
|
121 |
+
},
|
122 |
+
{
|
123 |
+
question: "Which protocol does ExpressRoute use for dynamic routing?",
|
124 |
+
answers: [
|
125 |
+
"TCP",
|
126 |
+
"UDP",
|
127 |
+
"BGP",
|
128 |
+
"HTTP"
|
129 |
+
],
|
130 |
+
correct: 2
|
131 |
+
},
|
132 |
+
{
|
133 |
+
question: "What is the ExpressRoute premium add-on used for?",
|
134 |
+
answers: [
|
135 |
+
"Increased data storage",
|
136 |
+
"Global connectivity",
|
137 |
+
"Unlimited bandwidth",
|
138 |
+
"Free Microsoft 365 access"
|
139 |
+
],
|
140 |
+
correct: 1
|
141 |
+
},
|
142 |
+
{
|
143 |
+
question: "How many connections are required for redundancy in ExpressRoute?",
|
144 |
+
answers: [
|
145 |
+
"1",
|
146 |
+
"2",
|
147 |
+
"3",
|
148 |
+
"4"
|
149 |
+
],
|
150 |
+
correct: 1
|
151 |
+
},
|
152 |
+
{
|
153 |
+
question: "What does ExpressRoute Global Reach allow you to do?",
|
154 |
+
answers: [
|
155 |
+
"Connect multiple data centers via Microsoft's network",
|
156 |
+
"Access Microsoft services for free",
|
157 |
+
"Increase bandwidth limits",
|
158 |
+
"Enable dynamic scaling"
|
159 |
+
],
|
160 |
+
correct: 0
|
161 |
+
},
|
162 |
+
{
|
163 |
+
question: "Which Microsoft service supports ExpressRoute?",
|
164 |
+
answers: [
|
165 |
+
"Microsoft 365",
|
166 |
+
"Xbox Live",
|
167 |
+
"LinkedIn",
|
168 |
+
"GitHub"
|
169 |
+
],
|
170 |
+
correct: 0
|
171 |
+
},
|
172 |
+
{
|
173 |
+
question: "What is the minimum bandwidth for an ExpressRoute circuit?",
|
174 |
+
answers: [
|
175 |
+
"50 Mbps",
|
176 |
+
"100 Mbps",
|
177 |
+
"200 Mbps",
|
178 |
+
"500 Mbps"
|
179 |
+
],
|
180 |
+
correct: 0
|
181 |
+
},
|
182 |
+
{
|
183 |
+
question: "What protocol does Microsoft use for routing in ExpressRoute?",
|
184 |
+
answers: [
|
185 |
+
"OSPF",
|
186 |
+
"RIP",
|
187 |
+
"BGP",
|
188 |
+
"EIGRP"
|
189 |
+
],
|
190 |
+
correct: 2
|
191 |
+
},
|
192 |
+
{
|
193 |
+
question: "What feature does ExpressRoute Direct provide?",
|
194 |
+
answers: [
|
195 |
+
"Dual 100-Gbps connectivity",
|
196 |
+
"Single point of failure",
|
197 |
+
"Free support",
|
198 |
+
"Global internet access"
|
199 |
+
],
|
200 |
+
correct: 0
|
201 |
+
},
|
202 |
+
{
|
203 |
+
question: "Which of the following is a connectivity option for ExpressRoute?",
|
204 |
+
answers: [
|
205 |
+
"Point-to-point Ethernet",
|
206 |
+
"Wi-Fi",
|
207 |
+
"Bluetooth",
|
208 |
+
"Satellite"
|
209 |
+
],
|
210 |
+
correct: 0
|
211 |
+
},
|
212 |
+
{
|
213 |
+
question: "What is the purpose of the Local SKU in ExpressRoute?",
|
214 |
+
answers: [
|
215 |
+
"Cost-effective data transfer",
|
216 |
+
"Global connectivity",
|
217 |
+
"Increased bandwidth",
|
218 |
+
"Free cloud services"
|
219 |
+
],
|
220 |
+
correct: 0
|
221 |
+
},
|
222 |
+
{
|
223 |
+
question: "What does ExpressRoute offer over public internet connections?",
|
224 |
+
answers: [
|
225 |
+
"Higher security and reliability",
|
226 |
+
"Faster hardware upgrades",
|
227 |
+
"Global service guarantees",
|
228 |
+
"Lower latency for gaming"
|
229 |
+
],
|
230 |
+
correct: 0
|
231 |
+
}
|
232 |
+
];
|
233 |
|
234 |
+
let currentQuestionIndex = 0;
|
235 |
+
let remainingPieces = Array.from({ length: 12 }, (_, i) => `piece-${i + 1}`);
|
236 |
+
let score = 0;
|
237 |
+
let totalQuestions = 0;
|
238 |
+
let timer;
|
239 |
+
let timeLeft = 120;
|
240 |
|
241 |
+
const puzzleBoard = document.getElementById("puzzle-board");
|
242 |
+
const questionElement = document.getElementById("question");
|
243 |
+
const answersElement = document.getElementById("answers");
|
244 |
+
const resultElement = document.getElementById("result");
|
245 |
+
const timerElement = document.getElementById("timer");
|
|
|
246 |
|
247 |
+
function updateTimer() {
|
248 |
+
timerElement.textContent = `Time Remaining: ${timeLeft} seconds`;
|
249 |
+
if (timeLeft <= 0) {
|
250 |
+
clearInterval(timer);
|
251 |
+
endGame(false);
|
252 |
+
}
|
253 |
+
timeLeft--;
|
254 |
+
}
|
|
|
255 |
|
256 |
+
function getRandomHiddenPiece() {
|
257 |
+
const randomIndex = Math.floor(Math.random() * remainingPieces.length);
|
258 |
+
const pieceId = remainingPieces.splice(randomIndex, 1)[0];
|
259 |
+
return document.getElementById(pieceId);
|
260 |
+
}
|
261 |
|
262 |
+
function showQuestion() {
|
263 |
+
const question = questions[currentQuestionIndex];
|
264 |
+
questionElement.textContent = question.question;
|
265 |
+
answersElement.innerHTML = "";
|
|
|
266 |
|
267 |
+
question.answers.forEach((answer, index) => {
|
268 |
+
const button = document.createElement("button");
|
269 |
+
button.textContent = answer;
|
270 |
+
button.classList.add("answer");
|
271 |
+
button.addEventListener("click", () => checkAnswer(index));
|
272 |
+
answersElement.appendChild(button);
|
273 |
+
});
|
274 |
+
}
|
275 |
|
276 |
+
function checkAnswer(selected) {
|
277 |
+
const question = questions[currentQuestionIndex];
|
278 |
+
totalQuestions++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
|
280 |
+
if (selected === question.correct) {
|
281 |
+
resultElement.textContent = "Correct! A puzzle piece is removed.";
|
282 |
+
score++;
|
283 |
+
revealPiece();
|
284 |
+
} else {
|
285 |
+
resultElement.textContent = "Incorrect. Try again.";
|
286 |
+
}
|
287 |
|
288 |
+
currentQuestionIndex++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
|
290 |
+
if (currentQuestionIndex < questions.length && remainingPieces.length > 0) {
|
291 |
+
showQuestion();
|
292 |
+
} else {
|
293 |
+
clearInterval(timer);
|
294 |
+
endGame(true);
|
295 |
+
}
|
296 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
|
298 |
+
function revealPiece() {
|
299 |
+
const piece = getRandomHiddenPiece();
|
300 |
+
if (piece) {
|
301 |
+
piece.classList.add("hidden");
|
302 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
}
|
304 |
+
|
305 |
+
function endGame(isTimeRemaining) {
|
306 |
+
const percentage = Math.round((score / totalQuestions) * 100);
|
307 |
+
if (isTimeRemaining && percentage >= 70) {
|
308 |
+
resultElement.textContent = `Congratulations! You passed with a score of ${percentage}%.`;
|
309 |
+
} else {
|
310 |
+
resultElement.textContent = `Game Over! You scored ${percentage}%. Try again!`;
|
311 |
+
const retryButton = document.createElement("button");
|
312 |
+
retryButton.textContent = "Train Again";
|
313 |
+
retryButton.classList.add("answer");
|
314 |
+
retryButton.addEventListener("click", () => {
|
315 |
+
resetGame();
|
316 |
+
});
|
317 |
+
answersElement.innerHTML = "";
|
318 |
+
answersElement.appendChild(retryButton);
|
319 |
+
}
|
|
|
|
|
|
|
|
|
|
|
320 |
}
|
321 |
+
|
322 |
+
function resetGame() {
|
323 |
+
currentQuestionIndex = 0;
|
324 |
+
score = 0;
|
325 |
+
totalQuestions = 0;
|
326 |
+
timeLeft = 120;
|
327 |
+
remainingPieces = Array.from({ length: 12 }, (_, i) => `piece-${i + 1}`);
|
328 |
+
resultElement.textContent = "";
|
329 |
+
|
330 |
+
const pieces = document.querySelectorAll(".piece");
|
331 |
+
pieces.forEach(piece => {
|
332 |
+
piece.classList.remove("hidden");
|
333 |
+
});
|
334 |
+
|
335 |
+
timer = setInterval(updateTimer, 1000);
|
336 |
+
updateTimer();
|
337 |
+
showQuestion();
|
338 |
}
|
339 |
+
|
340 |
+
document.getElementById("start-btn").addEventListener("click", () => {
|
341 |
+
resetGame();
|
342 |
+
});
|
343 |
+
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
</body>
|
345 |
</html>
|