deva-el / index.html
jai0123's picture
make a quiz game for electronics diploma 2 minut timer and 20 question - Initial Deployment
49180dd verified
Raw History Blame Contribute Delete
20.9 kB
<!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>