-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadlinesync.js
More file actions
56 lines (48 loc) · 1.52 KB
/
readlinesync.js
File metadata and controls
56 lines (48 loc) · 1.52 KB
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
const readline = require('readline-sync');
// Ask for the user's name
const userName = readline.question("Enter your name: ");
console.log(`\nHello, ${userName}! Let's start the quiz.\n`);
// Score tracker
let score = 0;
// Question 1
let answer1 = readline.question("What is the data type of `42` in JavaScript? ");
if (answer1.trim().toLowerCase() === "number") {
console.log("Correct.\n");
score++;
} else {
console.log("Incorrect. The correct answer is: number\n");
}
// Question 2
let answer2 = readline.question("Which symbol is used for addition? ");
if (answer2.trim() === "+") {
console.log("Correct.\n");
score++;
} else {
console.log("Incorrect. The correct answer is: +\n");
}
// Question 3
let answer3 = readline.question("What does `typeof null` return? ");
if (answer3.trim().toLowerCase() === "object") {
console.log("Correct.\n");
score++;
} else {
console.log("Incorrect. The correct answer is: object\n");
}
// Question 4
let answer4 = readline.question("What is 10 % 3? (Enter a number) ");
if (answer4.trim() === "1") {
console.log("Correct.\n");
score++;
} else {
console.log("Incorrect. The correct answer is: 1\n");
}
// Question 5
let answer5 = readline.question("Which keyword declares an unchangeable variable? ");
if (answer5.trim().toLowerCase() === "const") {
console.log("Correct.\n");
score++;
} else {
console.log("Incorrect. The correct answer is: const\n");
}
// Display final score
console.log(`Quiz finished, ${userName}. Your score: ${score}/5.\n`);