-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (25 loc) · 710 Bytes
/
script.js
File metadata and controls
29 lines (25 loc) · 710 Bytes
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
const questions = [
{
question: "What is the capital of India?",
answer: "Delhi"
},
{
question: "What is 2 + 2?",
answer: "4"
},
{
question: "Which language runs in a web browser?",
answer: "JavaScript"
}
];
let score = 0;
for (let i = 0; i < questions.length; i++) {
let userAnswer = prompt(questions[i].question); // Shows a popup box in browser
if (userAnswer && userAnswer.toLowerCase() === questions[i].answer.toLowerCase()) {
console.log(`✅ Q${i + 1}: Correct!`);
score++;
} else {
console.log(`❌ Q${i + 1}: Incorrect. Correct answer is "${questions[i].answer}".`);
}
}
console.log(`\n🎯 You scored ${score} out of ${questions.length}`);