File size: 20,943 Bytes
49180dd c598d52 | 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 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Electronics Diploma Quiz</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<style>
.progress-ring__circle {
transition: stroke-dashoffset 0.35s;
transform: rotate(-90deg);
transform-origin: 50% 50%;
}
.option:hover {
transform: translateY(-2px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.option.correct {
background-color: #10B981 !important;
color: white !important;
}
.option.incorrect {
background-color: #EF4444 !important;
color: white !important;
}
</style>
</head>
<body class="bg-gray-100 min-h-screen font-sans">
<div id="app" class="container mx-auto px-4 py-8">
<!-- Start Screen -->
<div id="start-screen" class="max-w-3xl mx-auto bg-white rounded-xl shadow-md overflow-hidden p-8 text-center" data-aos="zoom-in">
<div class="mb-6">
<i data-feather="cpu" class="w-16 h-16 mx-auto text-blue-500"></i>
</div>
<h1 class="text-3xl font-bold text-gray-800 mb-4">Electronics Diploma Quiz</h1>
<p class="text-gray-600 mb-6">Test your knowledge with 20 challenging questions. You have 2 minutes to complete the quiz!</p>
<button id="start-btn" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-3 px-8 rounded-full transition duration-300 transform hover:scale-105">
Start Quiz
</button>
</div>
<!-- Quiz Container -->
<div id="quiz-container" class="hidden max-w-3xl mx-auto bg-white rounded-xl shadow-md overflow-hidden">
<!-- Quiz Header -->
<div class="flex justify-between items-center p-6 border-b border-gray-200">
<div class="flex items-center">
<i data-feather="clock" class="w-5 h-5 text-gray-500 mr-2"></i>
<div class="relative">
<svg class="w-12 h-12">
<circle class="text-gray-200" stroke-width="4" stroke="currentColor" fill="transparent" r="16" cx="20" cy="20" />
<circle id="timer-circle" class="progress-ring__circle text-blue-500" stroke-width="4" stroke-dasharray="100" stroke-dashoffset="0" stroke-linecap="round" stroke="currentColor" fill="transparent" r="16" cx="20" cy="20" />
</svg>
<span id="timer" class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-sm font-bold">120</span>
</div>
</div>
<div class="text-gray-700 font-medium">
Question <span id="current-question">1</span>/20
</div>
</div>
<!-- Question Area -->
<div class="p-6">
<h2 id="question" class="text-xl font-semibold text-gray-800 mb-6"></h2>
<div id="options" class="grid grid-cols-1 md:grid-cols-2 gap-4"></div>
</div>
<!-- Navigation -->
<div class="flex justify-between p-6 border-t border-gray-200">
<button id="prev-btn" class="bg-gray-200 hover:bg-gray-300 text-gray-700 font-bold py-2 px-4 rounded-lg transition duration-300 flex items-center">
<i data-feather="arrow-left" class="w-4 h-4 mr-2"></i> Previous
</button>
<button id="next-btn" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded-lg transition duration-300 flex items-center">
Next <i data-feather="arrow-right" class="w-4 h-4 ml-2"></i>
</button>
<button id="submit-btn" class="hidden bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded-lg transition duration-300 flex items-center">
Submit <i data-feather="check" class="w-4 h-4 ml-2"></i>
</button>
</div>
</div>
<!-- Results Screen -->
<div id="results-screen" class="hidden max-w-3xl mx-auto bg-white rounded-xl shadow-md overflow-hidden p-8 text-center">
<div class="mb-6">
<i data-feather="award" class="w-16 h-16 mx-auto text-yellow-500"></i>
</div>
<h1 class="text-3xl font-bold text-gray-800 mb-4">Quiz Completed!</h1>
<div class="text-5xl font-bold text-blue-500 mb-6">
<span id="score">0</span>/20
</div>
<p id="result-message" class="text-gray-600 mb-6"></p>
<div class="flex justify-center space-x-4">
<button id="restart-btn" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-6 rounded-lg transition duration-300">
Restart Quiz
</button>
<button id="review-btn" class="bg-gray-200 hover:bg-gray-300 text-gray-700 font-bold py-2 px-6 rounded-lg transition duration-300">
Review Answers
</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
feather.replace();
AOS.init();
// Quiz questions
const questions = [
{
question: "What is the unit of electrical resistance?",
options: ["Volt", "Ampere", "Ohm", "Watt"],
answer: 2
},
{
question: "Which component stores electrical charge?",
options: ["Resistor", "Inductor", "Capacitor", "Transistor"],
answer: 2
},
{
question: "What does LED stand for?",
options: ["Light Emitting Diode", "Liquid Emitting Display", "Light Energy Detector", "Low Energy Device"],
answer: 0
},
{
question: "Which law states that current is directly proportional to voltage?",
options: ["Faraday's Law", "Ohm's Law", "Kirchhoff's Law", "Lenz's Law"],
answer: 1
},
{
question: "What is the main function of a rectifier?",
options: ["Convert AC to DC", "Convert DC to AC", "Amplify signals", "Store energy"],
answer: 0
},
{
question: "Which transistor configuration has the highest input impedance?",
options: ["Common Emitter", "Common Base", "Common Collector", "All have same impedance"],
answer: 2
},
{
question: "What is the typical voltage drop across a silicon diode?",
options: ["0.2V", "0.7V", "1.2V", "2.0V"],
answer: 1
},
{
question: "Which logic gate produces a HIGH output only when all inputs are HIGH?",
options: ["AND", "OR", "NOT", "NAND"],
answer: 0
},
{
question: "What is the frequency of standard household AC power in most countries?",
options: ["50Hz", "60Hz", "100Hz", "120Hz"],
answer: 0
},
{
question: "Which instrument is used to measure electric current?",
options: ["Voltmeter", "Ammeter", "Ohmmeter", "Wattmeter"],
answer: 1
},
{
question: "What is the primary function of a zener diode?",
options: ["Rectification", "Voltage regulation", "Amplification", "Switching"],
answer: 1
},
{
question: "Which type of motor is commonly used in ceiling fans?",
options: ["DC motor", "Stepper motor", "Induction motor", "Servo motor"],
answer: 2
},
{
question: "What is the color code for a 1kΩ resistor with 5% tolerance?",
options: ["Brown-Black-Red-Gold", "Brown-Black-Orange-Gold", "Red-Black-Red-Gold", "Brown-Black-Black-Gold"],
answer: 1
},
{
question: "Which theorem is used to simplify complex circuits?",
options: ["Thevenin's Theorem", "Bernoulli's Theorem", "Pythagorean Theorem", "Bayes' Theorem"],
answer: 0
},
{
question: "What does PCB stand for in electronics?",
options: ["Power Control Board", "Printed Circuit Board", "Process Control Block", "Program Counter Board"],
answer: 1
},
{
question: "Which flip-flop has only one input?",
options: ["SR Flip-flop", "D Flip-flop", "JK Flip-flop", "T Flip-flop"],
answer: 1
},
{
question: "What is the typical gain of an operational amplifier in open-loop configuration?",
options: ["1", "10", "100", "100,000"],
answer: 3
},
{
question: "Which material is commonly used as a semiconductor?",
options: ["Copper", "Silicon", "Aluminum", "Silver"],
answer: 1
},
{
question: "What is the main purpose of a heat sink?",
options: ["To store heat", "To dissipate heat", "To generate heat", "To measure heat"],
answer: 1
},
{
question: "Which modulation technique is used in FM radio broadcasting?",
options: ["Amplitude Modulation", "Frequency Modulation", "Phase Modulation", "Pulse Modulation"],
answer: 1
}
];
// DOM elements
const startScreen = document.getElementById('start-screen');
const quizContainer = document.getElementById('quiz-container');
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 submitBtn = document.getElementById('submit-btn');
const restartBtn = document.getElementById('restart-btn');
const reviewBtn = document.getElementById('review-btn');
const questionElement = document.getElementById('question');
const optionsElement = document.getElementById('options');
const currentQuestionElement = document.getElementById('current-question');
const timerElement = document.getElementById('timer');
const timerCircle = document.getElementById('timer-circle');
const scoreElement = document.getElementById('score');
const resultMessageElement = document.getElementById('result-message');
// Quiz variables
let currentQuestionIndex = 0;
let score = 0;
let timer;
let timeLeft = 120; // 2 minutes in seconds
let userAnswers = Array(questions.length).fill(null);
let quizCompleted = false;
// Initialize the quiz
function initQuiz() {
startScreen.classList.add('hidden');
quizContainer.classList.remove('hidden');
loadQuestion();
startTimer();
}
// Load question
function loadQuestion() {
const question = questions[currentQuestionIndex];
questionElement.textContent = question.question;
optionsElement.innerHTML = '';
question.options.forEach((option, index) => {
const optionElement = document.createElement('button');
optionElement.className = 'option bg-gray-100 hover:bg-gray-200 text-gray-800 p-4 rounded-lg transition duration-300 text-left';
// Check if user has already selected this option
if (userAnswers[currentQuestionIndex] === index) {
optionElement.classList.add('bg-blue-100', 'border-2', 'border-blue-500');
}
optionElement.innerHTML = `
<span class="font-bold mr-2">${String.fromCharCode(65 + index)}.</span>
<span>${option}</span>
`;
optionElement.addEventListener('click', () => selectOption(index));
optionsElement.appendChild(optionElement);
});
currentQuestionElement.textContent = currentQuestionIndex + 1;
// Update navigation buttons
prevBtn.disabled = currentQuestionIndex === 0;
nextBtn.disabled = false;
nextBtn.classList.remove('hidden');
submitBtn.classList.add('hidden');
if (currentQuestionIndex === questions.length - 1) {
nextBtn.classList.add('hidden');
submitBtn.classList.remove('hidden');
}
}
// Select option
function selectOption(optionIndex) {
// Remove all selected classes
document.querySelectorAll('.option').forEach(option => {
option.classList.remove('bg-blue-100', 'border-2', 'border-blue-500');
});
// Add selected class to clicked option
const selectedOption = document.querySelectorAll('.option')[optionIndex];
selectedOption.classList.add('bg-blue-100', 'border-2', 'border-blue-500');
// Store user answer
userAnswers[currentQuestionIndex] = optionIndex;
}
// Next question
function nextQuestion() {
if (currentQuestionIndex < questions.length - 1) {
currentQuestionIndex++;
loadQuestion();
}
}
// Previous question
function prevQuestion() {
if (currentQuestionIndex > 0) {
currentQuestionIndex--;
loadQuestion();
}
}
// Submit quiz
function submitQuiz() {
clearInterval(timer);
quizCompleted = true;
calculateScore();
showResults();
}
// Calculate score
function calculateScore() {
score = 0;
for (let i = 0; i < questions.length; i++) {
if (userAnswers[i] === questions[i].answer) {
score++;
}
}
}
// Show results
function showResults() {
quizContainer.classList.add('hidden');
resultsScreen.classList.remove('hidden');
scoreElement.textContent = score;
// Set result message based on score
let message;
if (score === questions.length) {
message = "Perfect! You're an electronics expert!";
} else if (score >= questions.length * 0.8) {
message = "Excellent work! You have strong electronics knowledge.";
} else if (score >= questions.length * 0.6) {
message = "Good job! You have a solid understanding of electronics.";
} else if (score >= questions.length * 0.4) {
message = "Not bad! Keep studying to improve your knowledge.";
} else {
message = "Keep practicing! Review the basics to strengthen your understanding.";
}
resultMessageElement.textContent = message;
}
// Restart quiz
function restartQuiz() {
currentQuestionIndex = 0;
score = 0;
timeLeft = 120;
userAnswers = Array(questions.length).fill(null);
quizCompleted = false;
resultsScreen.classList.add('hidden');
startScreen.classList.remove('hidden');
// Reset timer display
timerElement.textContent = timeLeft;
timerCircle.setAttribute('stroke-dashoffset', '0');
}
// Review answers
function reviewAnswers() {
currentQuestionIndex = 0;
resultsScreen.classList.add('hidden');
quizContainer.classList.remove('hidden');
loadQuestion();
// Highlight correct and incorrect answers
for (let i = 0; i < questions.length; i++) {
const question = questions[i];
const userAnswer = userAnswers[i];
if (userAnswer !== null) {
const options = document.querySelectorAll('.option');
options[question.answer].classList.add('correct');
if (userAnswer !== question.answer) {
options[userAnswer].classList.add('incorrect');
}
}
}
// Disable option selection during review
document.querySelectorAll('.option').forEach(option => {
option.style.pointerEvents = 'none';
});
// Update navigation buttons
prevBtn.disabled = currentQuestionIndex === 0;
nextBtn.disabled = false;
nextBtn.classList.remove('hidden');
submitBtn.classList.add('hidden');
}
// Start timer
function startTimer() {
const circumference = 2 * Math.PI * 16;
timerCircle.setAttribute('stroke-dasharray', circumference);
timerCircle.setAttribute('stroke-dashoffset', 0);
timer = setInterval(() => {
timeLeft--;
timerElement.textContent = timeLeft;
// Update progress ring
const offset = circumference - (timeLeft / 120) * circumference;
timerCircle.setAttribute('stroke-dashoffset', offset);
// Change color when time is running low
if (timeLeft <= 30) {
timerCircle.classList.remove('text-blue-500');
timerCircle.classList.add('text-red-500');
}
if (timeLeft <= 0) {
clearInterval(timer);
if (!quizCompleted) {
submitQuiz();
}
}
}, 1000);
}
// Event listeners
startBtn.addEventListener('click', initQuiz);
nextBtn.addEventListener('click', nextQuestion);
prevBtn.addEventListener('click', prevQuestion);
submitBtn.addEventListener('click', submitQuiz);
restartBtn.addEventListener('click', restartQuiz);
reviewBtn.addEventListener('click', reviewAnswers);
});
</script>
<script>feather.replace();</script>
<script>AOS.init();</script>
</body>
</html>
|