File size: 18,137 Bytes
ac20a0a 6f6a8fb | 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Computer Engineering Quiz</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.globe.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<style>
#vanta-bg {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.quiz-container {
backdrop-filter: blur(8px);
background-color: rgba(255, 255, 255, 0.85);
}
.option:hover {
transform: translateY(-2px);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.timer-pulse {
animation: pulse 1s infinite;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
</style>
</head>
<body class="min-h-screen flex items-center justify-center p-4">
<div id="vanta-bg"></div>
<div class="quiz-container max-w-4xl w-full rounded-xl shadow-2xl overflow-hidden p-8 transition-all duration-300">
<!-- Start Screen -->
<div id="start-screen" class="text-center">
<h1 class="text-4xl font-bold text-blue-800 mb-6">Computer Engineering Quiz</h1>
<p class="text-lg text-gray-700 mb-8">Test your knowledge with 20 challenging questions in 2 minutes!</p>
<div class="flex items-center justify-center mb-8">
<i data-feather="cpu" class="w-16 h-16 text-blue-600"></i>
</div>
<button id="start-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-8 rounded-full text-lg transition-all duration-300 transform hover:scale-105">
Start Quiz
</button>
</div>
<!-- Quiz Screen -->
<div id="quiz-screen" class="hidden">
<div class="flex justify-between items-center mb-8">
<div id="timer" class="bg-red-500 text-white px-4 py-2 rounded-full font-bold text-lg flex items-center timer-pulse">
<i data-feather="clock" class="mr-2"></i>
<span id="time">02:00</span>
</div>
<div class="bg-blue-100 text-blue-800 px-4 py-2 rounded-full font-bold">
Question <span id="current-question">1</span>/20
</div>
</div>
<div class="mb-8">
<h2 id="question" class="text-2xl font-semibold text-gray-800 mb-6"></h2>
<div id="options" class="grid grid-cols-1 md:grid-cols-2 gap-4"></div>
</div>
<div class="flex justify-between">
<button id="prev-btn" class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-6 rounded transition-all">
<i data-feather="arrow-left" class="mr-2"></i> Previous
</button>
<button id="next-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded transition-all">
Next <i data-feather="arrow-right" class="ml-2"></i>
</button>
</div>
</div>
<!-- Results Screen -->
<div id="results-screen" class="hidden text-center">
<h1 class="text-4xl font-bold text-blue-800 mb-6">Quiz Completed!</h1>
<div class="flex justify-center mb-8">
<div class="w-32 h-32 rounded-full bg-blue-100 flex items-center justify-center">
<i data-feather="award" class="w-16 h-16 text-yellow-500"></i>
</div>
</div>
<p class="text-xl mb-2">Your score: <span id="score" class="font-bold text-blue-600">0</span>/20</p>
<p id="result-message" class="text-lg text-gray-700 mb-8"></p>
<button id="restart-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-8 rounded-full text-lg transition-all">
Try Again
</button>
</div>
</div>
<script>
feather.replace();
// Vanta.js background
VANTA.GLOBE({
el: "#vanta-bg",
mouseControls: true,
touchControls: true,
gyroControls: false,
minHeight: 200.00,
minWidth: 200.00,
scale: 1.00,
scaleMobile: 1.00,
color: 0x3b82f6,
backgroundColor: 0xf8fafc,
size: 0.8
});
// Quiz questions
const questions = [
{
question: "What does CPU stand for?",
options: [
"Central Processing Unit",
"Computer Processing Unit",
"Central Process Unit",
"Computer Process Unit"
],
answer: 0
},
{
question: "Which of these is a volatile memory?",
options: [
"ROM",
"EEPROM",
"RAM",
"HDD"
],
answer: 2
},
{
question: "What is the binary equivalent of decimal 10?",
options: [
"1010",
"1001",
"1100",
"1110"
],
answer: 0
},
{
question: "Which protocol is used to send email?",
options: [
"SMTP",
"HTTP",
"FTP",
"TCP"
],
answer: 0
},
{
question: "What does SQL stand for?",
options: [
"Structured Query Language",
"Sequential Query Language",
"Standard Query Language",
"Simple Query Language"
],
answer: 0
},
{
question: "Which gate produces a 0 output only when all inputs are 1?",
options: [
"AND",
"OR",
"NAND",
"NOR"
],
answer: 2
},
{
question: "What is the main purpose of an operating system?",
options: [
"To manage hardware resources",
"To create documents",
"To browse the internet",
"To play games"
],
answer: 0
},
{
question: "Which of these is not a programming paradigm?",
options: [
"Object-oriented",
"Functional",
"Procedural",
"Compiled"
],
answer: 3
},
{
question: "What does API stand for?",
options: [
"Application Programming Interface",
"Application Process Interface",
"Automated Programming Interface",
"Automated Process Interface"
],
answer: 0
},
{
question: "Which data structure uses FIFO principle?",
options: [
"Stack",
"Queue",
"Tree",
"Graph"
],
answer: 1
},
{
question: "What is the time complexity of binary search?",
options: [
"O(1)",
"O(log n)",
"O(n)",
"O(n²)"
],
answer: 1
},
{
question: "Which of these is not a valid IP address?",
options: [
"192.168.1.1",
"256.0.0.1",
"172.16.254.1",
"10.0.0.1"
],
answer: 1
},
{
question: "What does IDE stand for?",
options: [
"Integrated Development Environment",
"Interactive Development Environment",
"Integrated Design Environment",
"Interactive Design Environment"
],
answer: 0
},
{
question: "Which component converts AC to DC in a computer?",
options: [
"CPU",
"GPU",
"PSU",
"RAM"
],
answer: 2
},
{
question: "What is the purpose of a compiler?",
options: [
"To execute code line by line",
"To translate high-level code to machine code",
"To debug code",
"To format code"
],
answer: 1
},
{
question: "Which of these is a non-linear data structure?",
options: [
"Array",
"Linked List",
"Tree",
"Queue"
],
answer: 2
},
{
question: "What does DNS stand for?",
options: [
"Domain Name System",
"Dynamic Name Server",
"Domain Network System",
"Dynamic Network Server"
],
answer: 0
},
{
question: "Which sorting algorithm has the worst time complexity?",
options: [
"Merge Sort",
"Quick Sort",
"Bubble Sort",
"Heap Sort"
],
answer: 2
},
{
question: "What is the main function of a router?",
options: [
"To connect different networks",
"To amplify signals",
"To store data",
"To process graphics"
],
answer: 0
},
{
question: "Which of these is not a valid logic gate?",
options: [
"AND",
"OR",
"XOR",
"NOR"
],
answer: 3
}
];
// Quiz variables
let currentQuestion = 0;
let score = 0;
let timeLeft = 120; // 2 minutes in seconds
let timer;
let userAnswers = Array(questions.length).fill(null);
// DOM elements
const startScreen = document.getElementById('start-screen');
const quizScreen = document.getElementById('quiz-screen');
const resultsScreen = document.getElementById('results-screen');
const startBtn = document.getElementById('start-btn');
const prevBtn = document.getElementById('prev-btn');
const nextBtn = document.getElementById('next-btn');
const restartBtn = document.getElementById('restart-btn');
const questionElement = document.getElementById('question');
const optionsElement = document.getElementById('options');
const currentQuestionElement = document.getElementById('current-question');
const timeElement = document.getElementById('time');
const scoreElement = document.getElementById('score');
const resultMessageElement = document.getElementById('result-message');
// Start quiz
startBtn.addEventListener('click', () => {
startScreen.classList.add('hidden');
quizScreen.classList.remove('hidden');
loadQuestion();
startTimer();
});
// Restart quiz
restartBtn.addEventListener('click', () => {
resultsScreen.classList.add('hidden');
startScreen.classList.remove('hidden');
resetQuiz();
});
// Previous question
prevBtn.addEventListener('click', () => {
if (currentQuestion > 0) {
currentQuestion--;
loadQuestion();
}
});
// Next question
nextBtn.addEventListener('click', () => {
if (currentQuestion < questions.length - 1) {
currentQuestion++;
loadQuestion();
} else {
showResults();
}
});
// Load question
function loadQuestion() {
const question = questions[currentQuestion];
questionElement.textContent = question.question;
optionsElement.innerHTML = '';
question.options.forEach((option, index) => {
const optionElement = document.createElement('button');
optionElement.className = 'option bg-white border border-gray-300 rounded-lg p-4 text-left hover:bg-blue-50 transition-all cursor-pointer';
optionElement.textContent = option;
// Highlight selected answer
if (userAnswers[currentQuestion] === index) {
optionElement.classList.add('bg-blue-100', 'border-blue-400');
}
optionElement.addEventListener('click', () => {
// Remove selection from all options
document.querySelectorAll('.option').forEach(opt => {
opt.classList.remove('bg-blue-100', 'border-blue-400');
});
// Add selection to clicked option
optionElement.classList.add('bg-blue-100', 'border-blue-400');
userAnswers[currentQuestion] = index;
// Check if answer is correct
if (index === question.answer) {
score++;
} else if (userAnswers[currentQuestion] !== null && userAnswers[currentQuestion] !== question.answer) {
score = Math.max(0, score - 0.5); // Penalty for wrong answer
}
});
optionsElement.appendChild(optionElement);
});
currentQuestionElement.textContent = currentQuestion + 1;
// Disable previous button on first question
prevBtn.disabled = currentQuestion === 0;
prevBtn.classList.toggle('opacity-50', currentQuestion === 0);
// Change next button text on last question
nextBtn.textContent = currentQuestion === questions.length - 1 ? 'Finish' : 'Next';
nextBtn.innerHTML = currentQuestion === questions.length - 1 ? 'Finish <i data-feather="check-circle" class="ml-2"></i>' : 'Next <i data-feather="arrow-right" class="ml-2"></i>';
feather.replace();
}
// Start timer
function startTimer() {
timer = setInterval(() => {
timeLeft--;
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
timeElement.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
// Flash red when time is running out
if (timeLeft <= 30) {
timeElement.parentElement.classList.add('bg-red-600');
}
// End quiz when time is up
if (timeLeft <= 0) {
clearInterval(timer);
showResults();
}
}, 1000);
}
// Show results
function showResults() {
clearInterval(timer);
quizScreen.classList.add('hidden');
resultsScreen.classList.remove('hidden');
// Calculate final score
let finalScore = 0;
userAnswers.forEach((answer, index) => {
if (answer === questions[index].answer) {
finalScore++;
}
});
scoreElement.textContent = finalScore;
// Display result message
let message = "";
if (finalScore >= 18) {
message = "Excellent! You're a computer engineering expert!";
} else if (finalScore >= 14) {
message = "Great job! You have strong computer engineering knowledge.";
} else if (finalScore >= 10) {
message = "Good effort! Keep learning to improve your skills.";
} else {
message = "Keep practicing! Review the fundamentals to improve.";
}
resultMessageElement.textContent = message;
feather.replace();
}
// Reset quiz
function resetQuiz() {
currentQuestion = 0;
score = 0;
timeLeft = 120;
userAnswers = Array(questions.length).fill(null);
timeElement.textContent = "02:00";
timeElement.parentElement.classList.remove('bg-red-600');
}
</script>
</body>
</html>
|