-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (71 loc) · 1.42 KB
/
index.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// ex13: list some questions
var questions = [ questionOne = {
question: "What is my favorite fruit?",
answer: "apple"
},
questionTwo = {
question: "Which is my favorite sad song?",
answer: "Mann Bharya"
},
questionThree = {
question: "What is my favorite vegetable?",
answer: "ladyfinger"
},
questionFour = {
question: "Which is my favorite english series?",
answer: "Grey's Anatomy"
},
questionFive = {
question: "Which is my favorite hindi movie?",
answer: "Neerja"
},
questionSix = {
question: "What is my favorite hobby?",
answer: "puzzles"
},
questionSeven = {
question: "Who is my favorite actress?",
answer: "Kareena Kapoor Khan"
},
questionEight = {
question: "Do I like Sunrise or Sunset?",
answer: "Sunset"
}
];
var rs = require("readline-sync");
var count=0;
// ex14: use function to make a quiz
function welcome()
{
var userName = rs.question("Enter your name:");
console.log("Welcome " + userName + " to the quiz of Harshita");
}
function play(q , a)
{
var ans=rs.question(q);
if(ans.toUpperCase() === a.toUpperCase())
{
console.log("YAY! Correct Answer");
count = count + 1;
}
else
{
console.log("NAY! Wrong Answer");
}
}
function game()
{
for(i = 0; i < questions.length; i++)
{
var currQ = questions[i];
play(currQ.question , currQ.answer);
}
}
// ex15: print the final score
function score()
{
console.log("Your score is : " + count);
}
welcome();
game();
score();