-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
193 lines (171 loc) · 4.74 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//Bandish Bandits Quiz
var readlineSync = require('readline-sync');
const chalk = require('chalk');
var score = 0;
//Data of HighScorer
var highScores = [
{
name: "Anushka",
score: 50
},
{
name: "Silky",
score: 44
},
{
name: "Farhin",
score: 43
},
{
name: "Jazzy",
score: 42
},
{
name: "Jenny",
score: 41
}
];
console.log(chalk.bold.yellowBright("Hello World!"));
//Take user's name and greet them
var userName = readlineSync.question(chalk.bold.cyan("What's your name? "));
console.log(chalk.red.bold.bgWhite("\nWelcome " + userName + " to the *Bandish Bandits* Quiz!!!!\n"));
//Quiz Rules
console.log(chalk.bold.yellowBright("**QUIZ RULES**"));
console.log(chalk.bold.blue("\t 1. There will total of 10 questions.\n\t 2. For each correct answer there is 5 marks.\n\t 3. For every wrong answer there is -1 marks.\n\t 4. Total score will be displayed at the end of quiz.\n\t 5. Answer using A,B,C,D alphabets Only."));
//Ask user whether they wants to play or not
var playGame = readlineSync.question("Are you excited to play the Quiz\nSelect [yes/no] ");
if(playGame.toLowerCase() === "yes"){
console.log("You choose to play quiz.\nHere we go!");
//Array of Q/A
var quizData = [
{
question:`1. What is Radhe's stage name?
A. Masked Man
B. Iron Man
C. Super Man
D. Krishna
Enter your answer: `,
answer:"A"
},
{
question:`2. The whole series is mainly shot in?
A. Jaipur
B. Jodhpur
C. Bikaner
D. Udaipur
Enter your answer: `,
answer:"B"
},
{
question:`3. How much loan did Radhe's father take from the bank?
A. 50 Lakhs
B. 7 Crore
C. 1.5 Crore
D. 1 Crore
Enter your answer: `,
answer:"C"
},
{
question:`4. What is the color of Tamanna's hairstreaks?
A. Red
B. Green
C. Purple
D. Blue
Enter your answer: `,
answer:"D"
},
{
question:`5. Tamanna got famous after which song?
A. Couple Goals
B. Phas Gaye
C. Sajan Bin
D. Yolo Jeelo
Enter your answer: `,
answer:"D"
},
{
question:`6. Which song Radhe and Tamanna sing together?
A. Couple Goals
B. Mastiyappa
C. Phas Gaye
D. Chedhkhaniya
Enter your answer: `,
answer:"C"
},
{
question:`7. What's the name of the instrument Devendra had the patent of ?
A. Guitar
B. Audlin
C. Devlin
D. Flute
Enter your answer: `,
answer:"B"
},
{
question:`8. Tamanna's dream is to sing with which pop star?
A. Queen Eli
B. Lady Gaga
C. Madona
D. Eneique Iglesias
Enter your answer: `,
answer:"A"
},
{
question:`9. What was the name of the girl with whom Radhe was going to get married?
A. Sanya
B. Sugandha
C. Sandhya
D. Shreya
Enter your answer: `,
answer:"C"
},
{
question:`10. Radhe's father asked him to do which job at the Palace?
A. Accountant
B. Watchman
C. Assistant Bookkepper
D. Doorman
Enter your answer: `,
answer:"A"
}
];
//Quiz function
function quiz(question,answer){
var userAnswer = readlineSync.question(chalk.blue.bold(question));
if(userAnswer.toUpperCase() === answer){
console.log(chalk.green("You're right!"));
score = score + 5;
}
else{
console.log(chalk.red("Sorry! You're wrong!"));
score = score - 1;
}
console.log("Current score : ",chalk.yellow.bold(score));
console.log("********************");
}
//for loop for taking question and answer from array and passing it to the quiz function
for(var i = 0; i<quizData.length; i++){
quiz(quizData[i].question,quizData[i].answer);
}
//printing the final score to the user
console.log(chalk.black.bold.bgWhite("Your Final Score: " + score));
console.log("********************\n");
console.log(chalk.bold.magenta("Current High Scorer"));
console.log("-----------------------------");
console.log("|\tName\t\t|\tScore\t|")
for(var i=0; i<highScores.length; i++){
console.log("|\t" +highScores[i].name + "\t\t|\t" + highScores[i].score + "\t\t|");
}
console.log("-----------------------------");
if(score>=highScores[0].score){
console.log(chalk.bold.blue("Yay!!! Congratulations!\nYou have scored a HIGH SCORE.\n"));
console.log(chalk.bgWhite.yellow("Please share a screenshot of your score & I'll update the scoreboard.\n"));
}
console.log(chalk.bold.red("Thank you so much for participating in this quiz."));
}
else{
console.log(chalk.bold.greenBright("Sorry! You quit the game."));
console.log("Always rememeber this quote.");
console.log("****************************");
console.log(chalk.bold.red("Life has two rules:\n#1 Never Quit\n#2 Remember Rule #1"));
}