⚡
Create a Quiz Game 🎮
Intermediate
155 XP
65 min
Lesson Content
Create a Quiz Game 🎮
Build an interactive quiz game that tests knowledge. Perfect for learning platforms!
Quiz Structure
const questions = [
{
question: "What is JavaScript?",
options: ["A language", "A framework", "A library"],
correct: 0
}
];
let currentQuestion = 0;
let score = 0;
function showQuestion() {
const q = questions[currentQuestion];
// Display question and options
}
function checkAnswer(selected) {
if (selected === questions[currentQuestion].correct) {
score++;
}
currentQuestion++;
}Example Code
Create quiz game functionality
const questions = [
{ question: 'What is 2+2?', options: ['3', '4', '5'], correct: 1 },
{ question: 'What is JS?', options: ['Language', 'Framework'], correct: 0 }
];
let currentQuestion = 0;
let score = 0;
function checkAnswer(selected) {
if (selected === questions[currentQuestion].correct) {
score++;
console.log('Correct!');
} else {
console.log('Wrong!');
}
currentQuestion++;
}
checkAnswer(1);
checkAnswer(0);
console.log('Final score:', score);Expected Output:
Quiz game with scoring system
Study Tips
- •Read the theory content thoroughly before practicing
- •Review the example code to understand key concepts
- •Proceed to the Practice tab when you're ready to code