-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
241 lines (204 loc) · 6.59 KB
/
app.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import chalk from 'chalk';
import inquirer from 'inquirer';
import gradient from 'gradient-string';
import chalkAnimation from 'chalk-animation';
import figlet from 'figlet';
import { createSpinner } from 'nanospinner';
let playerName;
const sleep = (ms = 2000) => new Promise((r) => setTimeout(r, ms));
async function welcome() {
const rainbowTitle = chalkAnimation.rainbow(
'NODEJS QUIZ\n'
);
await sleep();
rainbowTitle.stop();
console.log(`
Hello!
Welcome to Nodejs Quiz
If you get any question wrong you ${chalk.bgRed('LOSE!!')}
So get all the questions right...
All the Best!!!
`);
}
async function handleAnswer(isCorrect) {
const spinner = createSpinner('Checking answer...').start();
await sleep();
if (isCorrect) {
spinner.success({ text: `Good ${playerName}. That's the correct answer` });
} else {
spinner.error({ text: `Quiz over, you lose ${playerName}!` });
process.exit(1);
}
}
async function askName() {
const answers = await inquirer.prompt({
name: 'player_name',
type: 'input',
message: 'What is your name?',
default() {
return 'Player';
},
});
playerName = answers.player_name;
}
function winner() {
console.clear();
figlet(`Congrats , ${playerName} !\n You have won the sum of $ 10 , 0 0 0 , 0 0 0`, (err, data) => {
console.log(gradient.pastel.multiline(data) + '\n');
console.log(
chalk.green(
``
)
);
process.exit(0);
});
}
async function question1() {
const answers = await inquirer.prompt({
name: 'question_1',
type: 'list',
message: 'Why code written in Node.JS is pretty fast although being written in JavaScript?\n',
choices: [
'Node.JS internally converts JavaScript code to Java based code and then execute the same',
'Node.JS internally converts JavaScript code to C based code and then execute the same',
"Being built on Google Chrome's V8 JavaScript Engine",
'None of the above',
],
});
return handleAnswer(answers.question_1 === "Being built on Google Chrome's V8 JavaScript Engine");
}
async function question2() {
const answers = await inquirer.prompt({
name: 'question_2',
type: 'list',
message: 'Which of the following is not a valid HTTP method?\n',
choices: [ 'get',
'header',
'post',
'put',
'patch'],
});
return handleAnswer(answers.question_2 === 'header');
}
async function question3() {
const answers = await inquirer.prompt({
name: 'question_3',
type: 'list',
message: 'Which of the following code print the name of operating system?\n',
choices: [ "console.log('type : ' + os.getType());",
"None of the above.",
"console.log('type : ' + os.type);",
"console.log('type : ' + os.type());"
],
});
return handleAnswer(answers.question_3 === "console.log('type : ' + os.type());");
}
async function question4() {
const answers = await inquirer.prompt({
name: 'question_4',
type: 'list',
message: 'What is Callback?\n',
choices: [ "Callback is an asynchronous equivalent for a function.",
"None of the above.",
"Callback is a technique in which a method call back the caller method.",
"Both of the above."
],
});
return handleAnswer(answers.question_4 === "Callback is an asynchronous equivalent for a function.");
}
async function question5() {
const answers = await inquirer.prompt({
name: 'question_5',
type: 'list',
message: ' Node js is a single threaded application but supports concurrency.\n',
choices: [ "true.",
"None of the above.",
"false.",
"Both of the above."
],
});
return handleAnswer(answers.question_5 === "true.");
}
async function question6() {
const answers = await inquirer.prompt({
name: 'question_6',
type: 'list',
message: ' What is the full form of npm? \n',
choices: [ "Node Project Manager",
"New Project Manager",
"New Package Manager",
"Node Package Manager"
],
});
return handleAnswer(answers.question_6 === "Node Package Manager");
}
async function question7() {
const answers = await inquirer.prompt({
name: 'question_7',
type: 'list',
message: ' _____ is an interactive shell that processes Node. \n',
choices: [ "REPL",
"REAL",
"RESP",
"None of the Above"
],
});
return handleAnswer(answers.question_7 === "REPL");
}
async function question8() {
const answers = await inquirer.prompt({
name: 'question_8',
type: 'list',
message: ' How can we expose node modules? \n',
choices: [ "expose",
"exports",
"requires",
"None of the Above"
],
});
return handleAnswer(answers.question_8 === "exports");
}
async function question9() {
const answers = await inquirer.prompt({
name: 'question_9',
type: 'list',
message: `
Which of the following statements are true?
1. NodeJS is multithreaded.
2. The Buffer class is a global class that can be accessed without importing a buffer module.`,
choices: [ "Both are True",
"Both are False",
"Statement 1 is True and Statement 2 is False",
"Statement 2 is True and Statement 1 is False"
],
});
return handleAnswer(answers.question_9 === "Statement 1 is True and Statement 2 is False");
}
async function question10() {
const answers = await inquirer.prompt({
name: 'question_10',
type: 'list',
message: 'When does a stream fire a data event?' ,
choices: [ "When there is Data to Read",
"When there is Data to Write",
"Where there is no Data available",
"Node of the Above"
],
});
return handleAnswer(answers.question_10 === "When there is Data to Write");
}
// Run it with top-level await
console.clear();
await welcome();
await askName();
await question1();
await question2();
await question3();
await question4();
await question5();
await question6();
await question7();
await question8();
await question9();
await question10();
winner();