deva-co / index.html
jai0123's picture
make a quiz game for computer engineering studens with 2 minutes timer and live backround 20 question - Initial Deployment
ac20a0a verified
Raw History Blame Contribute Delete
18.1 kB
<!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>