Skip to content

Commit 4777b92

Browse files
committed
Initial Commit
0 parents  commit 4777b92

File tree

5 files changed

+1564
-0
lines changed

5 files changed

+1564
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
DS-STORE

desktop.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[.ShellClassInfo]
2+
IconResource=C:\Windows\System32\SHELL32.dll,243
3+
[ViewState]
4+
Mode=
5+
Vid=
6+
FolderType=Generic

index.js

Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
#!/usr/bin/env node
2+
3+
4+
/*
5+
/$$$$$ /$$$$$$ /$$ /$$ /$$$$$$$ /$$$$$$
6+
|__ $$ /$$__ $$ | $$ /$$/| $$__ $$ /$$__ $$
7+
| $$| $$ \__/ | $$ /$$/ | $$ \ $$| $$ \__/
8+
| $$| $$$$$$ /$$$$$$| $$$$$/ | $$$$$$$ | $$
9+
/$$ | $$ \____ $$|______/| $$ $$ | $$__ $$| $$
10+
| $$ | $$ /$$ \ $$ | $$\ $$ | $$ \ $$| $$ $$
11+
| $$$$$$/| $$$$$$/ | $$ \ $$| $$$$$$$/| $$$$$$/
12+
\______/ \______/ |__/ \__/|_______/ \______/
13+
*/
14+
15+
16+
import chalk from 'chalk';
17+
import inquirer from 'inquirer';
18+
import gradient from 'gradient-string';
19+
import chalkAnimation from 'chalk-animation';
20+
import figlet from 'figlet';
21+
import { createSpinner } from 'nanospinner';
22+
23+
let playerName;
24+
25+
const sleep = (ms = 2000) => new Promise((r) => setTimeout(r, ms));
26+
27+
async function welcome() {
28+
const rainbowTitle = chalkAnimation.rainbow(
29+
'Who Wants To Win The JavaScript KBC ? \n'
30+
);
31+
32+
await sleep();
33+
rainbowTitle.stop();
34+
35+
console.log(`
36+
${chalk.bgBlue('HOW TO PLAY')}
37+
I am a process on your computer.
38+
If you get any question wrong I will be ${chalk.bgRed('killed')}
39+
So get all the questions right...
40+
41+
`);
42+
}
43+
44+
async function handleAnswer(isCorrect) {
45+
const spinner = createSpinner('Checking answer...').start();
46+
await sleep();
47+
48+
if (isCorrect) {
49+
spinner.success({ text: `Nice Work ${playerName}. That's A legit Answer` });
50+
} else {
51+
spinner.error({ text: `💀💀💀 Game Over, Unfortunately You Lost The Prize Money . We're Sorry For You , ${playerName}!` });
52+
process.exit(1);
53+
}
54+
}
55+
56+
async function askName() {
57+
const answers = await inquirer.prompt({
58+
name: 'player_name',
59+
type: 'input',
60+
message: 'What Is Your Name?',
61+
default() {
62+
return 'Player';
63+
},
64+
});
65+
66+
playerName = answers.player_name;
67+
}
68+
69+
function winner() {
70+
console.clear();
71+
figlet(`Congrats , ${playerName} !\n Rs. 1 0 , 0 0 0 , 0 0 0`, (err, data) => {
72+
console.log(gradient.pastel.multiline(data) + '\n');
73+
74+
console.log(
75+
chalk.green(
76+
`Programming Is Not Solely About Your Knowledge; It's About Adding A Touch Of Flair To The Command Line !`
77+
)
78+
);
79+
process.exit(0);
80+
});
81+
}
82+
83+
// Question 1
84+
async function question1() {
85+
const answers = await inquirer.prompt({
86+
name: 'question_1',
87+
type: 'list',
88+
message: 'Who is often referred to as the "father of JavaScript"?\n',
89+
choices: [
90+
'Brendan Eich',
91+
'Mark Zuckerberg',
92+
'Tim Berners-Lee',
93+
'Bill Gates',
94+
],
95+
});
96+
97+
return handleAnswer(answers.question_1 === 'Brendan Eich');
98+
}
99+
100+
// Question 2
101+
async function question2() {
102+
const answers = await inquirer.prompt({
103+
name: 'question_2',
104+
type: 'list',
105+
message: 'What is the primary purpose of JavaScript in web development?\n',
106+
choices: [
107+
'Styling web pages',
108+
'Creating databases',
109+
'Enhancing user interfaces',
110+
'Sending emails',
111+
],
112+
});
113+
114+
return handleAnswer(answers.question_2 === 'Enhancing user interfaces');
115+
}
116+
117+
// Question 3
118+
async function question3() {
119+
const answers = await inquirer.prompt({
120+
name: 'question_3',
121+
type: 'list',
122+
message: 'Which keyword is used to declare a constant variable in JavaScript?\n',
123+
choices: ['var', 'let', 'const', 'fixed'],
124+
});
125+
126+
return handleAnswer(answers.question_3 === 'const');
127+
}
128+
129+
// Question 4
130+
async function question4() {
131+
const answers = await inquirer.prompt({
132+
name: 'question_4',
133+
type: 'list',
134+
message: 'Which of the following is not a valid JavaScript data type?\n',
135+
choices: [
136+
'Number',
137+
'String',
138+
'Character',
139+
'Boolean',
140+
],
141+
});
142+
143+
return handleAnswer(answers.question_4 === 'Character');
144+
}
145+
146+
// Question 5
147+
async function question5() {
148+
const answers = await inquirer.prompt({
149+
name: 'question_5',
150+
type: 'list',
151+
message: 'What does the "DOM" stand for in web development?\n',
152+
choices: [
153+
'Document Object Model',
154+
'Data Output Mechanism',
155+
'Digital Object Manager',
156+
'Document Orientation Module',
157+
],
158+
});
159+
160+
return handleAnswer(answers.question_5 === 'Document Object Model');
161+
}
162+
163+
// Question 6
164+
async function question6() {
165+
const answers = await inquirer.prompt({
166+
name: 'question_6',
167+
type: 'list',
168+
message: 'Which keyword is used to declare a variable in JavaScript?\n',
169+
choices: ['var', 'let', 'const', 'variable'],
170+
});
171+
172+
return handleAnswer(answers.question_6 === 'var');
173+
}
174+
175+
// Question 7
176+
async function question7() {
177+
const answers = await inquirer.prompt({
178+
name: 'question_7',
179+
type: 'list',
180+
message: 'What does the acronym "DOM" stand for in web development?\n',
181+
choices: [
182+
'Document Object Model',
183+
'Data Object Model',
184+
'Design Object Model',
185+
'Document Object Method',
186+
],
187+
});
188+
189+
return handleAnswer(answers.question_7 === 'Document Object Model');
190+
}
191+
192+
// Question 8
193+
async function question8() {
194+
const answers = await inquirer.prompt({
195+
name: 'question_8',
196+
type: 'list',
197+
message: 'Which built-in method removes the last element from an array and returns that element in JavaScript?\n',
198+
choices: ['pop()', 'shift()', 'splice()', 'push()'],
199+
});
200+
201+
return handleAnswer(answers.question_8 === 'pop()');
202+
}
203+
204+
// Question 9
205+
async function question9() {
206+
const answers = await inquirer.prompt({
207+
name: 'question_9',
208+
type: 'list',
209+
message: 'What is the purpose of the `addEventListener` method in JavaScript?\n',
210+
choices: [
211+
'To add a class to an element',
212+
'To execute a function when an event occurs',
213+
'To create a new DOM element',
214+
'To change the CSS style of an element',
215+
],
216+
});
217+
218+
return handleAnswer(answers.question_9 === 'To execute a function when an event occurs');
219+
}
220+
221+
// Question 10
222+
async function question10() {
223+
const answers = await inquirer.prompt({
224+
name: 'question_10',
225+
type: 'list',
226+
message: 'Which operator is used for strict equality in JavaScript?\n',
227+
choices: ['==', '===', '=', '!='],
228+
});
229+
230+
return handleAnswer(answers.question_10 === '===');
231+
}
232+
233+
// Question 11
234+
async function question11() {
235+
const answers = await inquirer.prompt({
236+
name: 'question_11',
237+
type: 'list',
238+
message: 'What is the purpose of the JavaScript `map()` function?\n',
239+
choices: [
240+
'To filter elements in an array',
241+
'To transform elements in an array',
242+
'To remove elements from an array',
243+
'To find the maximum value in an array',
244+
],
245+
});
246+
247+
return handleAnswer(answers.question_11 === 'To transform elements in an array');
248+
}
249+
250+
// Question 12
251+
async function question12() {
252+
const answers = await inquirer.prompt({
253+
name: 'question_12',
254+
type: 'list',
255+
message: 'In JavaScript, what is the result of adding a number and a string?\n',
256+
choices: [
257+
'An error',
258+
'The number is converted to a string and concatenated',
259+
'The string is converted to a number and added',
260+
'A random value is generated',
261+
],
262+
});
263+
264+
return handleAnswer(answers.question_12 === 'The number is converted to a string and concatenated');
265+
}
266+
267+
// Question 13
268+
async function question13() {
269+
const answers = await inquirer.prompt({
270+
name: 'question_13',
271+
type: 'list',
272+
message: 'Which method is used to remove the last element from an array and return it?\n',
273+
choices: ['pop()', 'shift()', 'splice()', 'push()'],
274+
});
275+
276+
return handleAnswer(answers.question_13 === 'pop()');
277+
}
278+
279+
// Question 14
280+
async function question14() {
281+
const answers = await inquirer.prompt({
282+
name: 'question_14',
283+
type: 'list',
284+
message: 'In JavaScript, what does the `NaN` value represent?\n',
285+
choices: [
286+
'Not a Number',
287+
'Zero',
288+
'Infinity',
289+
'Undefined',
290+
],
291+
});
292+
293+
return handleAnswer(answers.question_14 === 'Not a Number');
294+
}
295+
296+
// Question 15
297+
async function question15() {
298+
const answers = await inquirer.prompt({
299+
name: 'question_15',
300+
type: 'list',
301+
message: 'What is the purpose of the JavaScript `forEach()` method?\n',
302+
choices: [
303+
'To execute a function for each element in an array',
304+
'To create a new array with filtered elements',
305+
'To find the first element that matches a condition',
306+
'To sort the elements in an array',
307+
],
308+
});
309+
310+
return handleAnswer(answers.question_15 === 'To execute a function for each element in an array');
311+
}
312+
313+
314+
// Run it with top-level await
315+
console.clear();
316+
await welcome();
317+
await askName();
318+
await question1();
319+
await question2();
320+
await question3();
321+
await question4();
322+
await question5();
323+
await question6();
324+
await question7();
325+
await question8();
326+
await question9();
327+
await question10();
328+
await question11();
329+
await question12();
330+
await question13();
331+
await question14();
332+
await question15();
333+
winner();

0 commit comments

Comments
 (0)