-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
207 lines (189 loc) · 6.65 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
const readlineSync = require('readline-sync');
const chalk = require('chalk');
const log = console.log.bind(console);
const userName = readlineSync.question(chalk.blue("Hey There! Whats your name? "));
log(chalk.blue.bold('\nWelcome to the Quiz!', userName));
const leaderBoard = [
{
name: "Bilal",
score: 10
},
{
name: "Jon Snow",
score: 9
},
{
name: "Joey",
score: 8
}
]
let score = 0;
let levelScore = 0;
const questions = [
{
question: "Friends is set up in which city?",
options: ["a. Los Angeles", "b. New York", "c. Chicago", "d. Houston"],
answer: "b"
},
{
question: "What character does Joey play in the soap opera Days of our Lives?",
options: ["a. Kevin", "b. Michael", "c. Ceaser", "d. Drake"],
answer: "d"
}, {
question: "What kind of pet was Marcel?",
options: ["a. Dog", "b. Cat", "c. Monkey", "d. Fish"],
answer: "c"
}, {
question: "To breakup with Janice,, where does chandler say he is moving?",
options: ["a. India", "b. Vermont", "c. Lebanon", "d. Yemen"],
answer: "d"
},
{
question: "What is name of Phoebe's Sister?",
options: ["a. Ursula", "b. Maeve", "c. Michael", "d. Rachel"],
answer: "a"
}
, {
question: "What is Joey's favorite food?",
options: ['a. Pizza', 'b. Burgers', 'c. Sushi', 'd. Ice cream'],
answer: 'a'
},
{
question: "Monica organises her towels into several categories. But how many?",
options: ["a. 9", "b. 6", "c. 4", "d. 11"],
answer: "d"
},
{
question: "What are Monica and Ross' parents called?",
options: ["a. Jack And Judy", "b. Jack And Jill", "c. Peter And Margaret", "d. Gerry And Mary"],
answer: "a"
},
{
question: "Chandler and Joey had two pets. What were they called?",
options: ["a. Don And Ivana", "b. Briand And Larry", "c. Don And Iva", "d. Chick Jr. And Duck Jr."],
answer: "d"
},
{
question: "What is the name of Joey’s acting agent?",
options: ["a. Andrea", "b. Estelle", "c. Carole", "d. Martha"],
answer: "b"
}, {
question: "Which job did Rachel’s fiancé Barry Farber do?",
options: ["a. Salesman", "b. Teacher", "c. Dentist", "d. Lawyer"],
answer: "c"
}, {
question: "Chandler and Ross were a band while they were at college. Can you remember the band's name?",
options: ["a. Mosh Bros", "b. The Rolling Stones", "c. The Beach", "d. Way/No Way"],
answer: "d"
}, {
question: "Ross is allergic to which kind of fruit?",
options: ["a. Apples", "b. Bananas", "c. Strawberries", "d. Kiwi"],
answer: "d"
}, {
question: "Monica dated a millionaire for a while. What was his name?",
options: ["a. Paul", "b. Pete", "c. Joe", "d. James"],
answer: "b"
}, {
question: "What is the name of Phoebe's alter-ego? ",
options: ["a. Phoebe Needy", "b. Monica Bing", "c. Regina Falange", "d. Elaine"],
answer: "c"
}
]
function viewLeaderBoard() {
log(chalk.greenBright("\nLeaderBoard\n"))
leaderBoard.forEach((item, index) => {
log(`Rank ${index + 1} : ${item.name} - Score:${item.score}`);
})
}
function checkAnswer(currentQuestion, answer) {
if (answer.toLowerCase() === questions[currentQuestion].answer) {
log(chalk.green('Correct!'));
score++;
levelScore++;
} else {
log(chalk.red('Incorrect!'));
}
log(chalk.greenBright.bold(`Your score is ${score}\n`));
}
function level(levelNumber) {
for (let i = (levelNumber - 1) * 5; i < levelNumber * 5; i++) {
log(chalk.bold("------------------"));
log(chalk.cyanBright(`Q${i + 1}->`, questions[i].question, "\n"));
questions[i].options.forEach(option => {
log(chalk.yellow.bold(option));
})
const answer = readlineSync.question(chalk.white.bold('\nYour answer: '), {
limit: ['a', 'b', 'c', 'd'],
caseSensitive: false
});
checkAnswer(i, answer);
}
}
function result() {
if (score === 15) {
log(chalk.green.bold('\nCongratulations! You have passed the quiz!'));
log(chalk.green.bold('You have scored a total of 15/15'));
log(chalk.green.bold('You are a true FRIENDS fan!'));
}
else if (score >= 10) {
log(chalk.green.bold('\nCongratulations! You have passed the quiz!'));
log(chalk.green.bold(`You have scored a total of ${score}/15`));
log(chalk.green.bold('You are an average FRIENDS fan!'));;
} else if (score >= 5) {
log(chalk.green.bold(`\nYou have scored a total of ${score}/15`));
log(chalk.red.bold('You are a weak FRIENDS fan!'));
} else {
log(chalk.red.bold(`\nYou have scored a total of ${score}/15`));
}
}
function game() {
log(chalk.bold("\nLEVEL 1"));
level(1);
if (levelScore >= 3) {
levelScore = 0;
log(chalk.bold("Congratulations! You passed the level 1"));
log(chalk.bold("\nLEVEL 2"));
level(2);
} else {
log(chalk.bold("Sorry! You failed the level 1"));
result();
return;
}
if (levelScore >= 3) {
levelScore = 0;
log(chalk.bold("Congratulations! You passed the level 2"));
log(chalk.bold("\nLEVEL 3"));
level(3);
result();
} else {
log(chalk.bold("Sorry! You failed the level 2"));
result();
return;
}
}
function app() {
log(chalk.yellow.bold("\nLets see how well do you know about FRIENDS"));
log(chalk.green.bold(
`\nSo here are the rules of the game:\n1. There are 3 levels in all and each level has 5 questions.\n2. You have to answer atleast 3/5 questions correctly to go to next level.\nALL THE BEST! Lets begin\n------------------------------`));
readlineSync.keyInPause(chalk.gray('\nPress any key to start the game...'));
game();
}
log(chalk.bold("\nWould you like to play the game or view the leaderboard"));
const playOrView = readlineSync.question(chalk.bold("\nType G for game and L for leaderboard: "), {
limit: ['g', 'l'],
caseSensitive: false
});
if (playOrView.toLowerCase() === "g") {
app();
viewLeaderBoard();
for (let i = 0; i < leaderBoard.length; i++) {
const item = leaderBoard[i];
if (score > item.score) {
log(chalk.green.bold(`\nCongratulations You have beaten ${item.name}'s score`))
log(chalk.cyan.bold("Please contact admin to update the leaderboard"));
break;
}
}
} else {
viewLeaderBoard();
}