-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
331 lines (262 loc) Β· 7.14 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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/usr/bin/env node
import chalk from "chalk";
import inquirer from "inquirer";
import gradient from "gradient-string";
import chalkAnimation from "chalk-animation";
import figlet from "figlet";
import yosay from "yosay";
import { createSpinner } from "nanospinner";
let playerName;
let score = 0;
// artificial delay
const sleep = (ms = 1500) => new Promise((r) => setTimeout(r, ms));
//function to listen to keypress
const keypress = async () => {
process.stdin.setRawMode(true);
return new Promise((resolve) =>
process.stdin.once("data", () => {
process.stdin.setRawMode(false);
resolve();
})
);
};
// welcome a new user
async function welcome() {
const rainbowTitle = chalkAnimation.rainbow(
"Welcome to Serjeel Ranjan's CLI \n"
);
await sleep(3000);
rainbowTitle.stop();
console.log(`
${chalk.bgBlue("WHAT DO I DO HERE?")}
Let us know each other a bit more.
And for that I will be asking you ${chalk.bgYellow("10 Questions")}
Let's see how you do.
`);
console.log(yosay(`Don't worry they will be ${chalk.blue("easy")}`));
console.log(chalk.bgGreen(`\npress any key to continue...`));
await keypress();
}
async function handleAnswer(optionScore) {
const spinner = createSpinner("Processing...").start();
await sleep();
spinner.success();
score += optionScore;
}
async function askName() {
console.clear();
console.log(yosay(`Don't be ${chalk.blue("shy")}`));
const answers = await inquirer.prompt({
name: "player_name",
type: "input",
message: `${chalk.bgRed("What name people call you with?")}\n`,
default() {
return "Anonymous";
},
});
playerName = answers.player_name;
}
function EndTheQuiz() {
console.clear();
figlet(`Woohoo! , ${playerName} !`, (err, data) => {
console.log(gradient.pastel.multiline(data) + "\n");
console.log(chalk.blue(`Our thoughts match `) + chalk.red(`${score}%`));
if (score >= 85) {
console.log(yosay(`${chalk.blue("Are you my clone?")} `));
} else if (score >= 75) {
console.log(yosay(`${chalk.blue("We have so much in common?")} `));
} else if (score >= 65) {
console.log(yosay(`${chalk.blue("We can get along pretty easily")} `));
} else {
console.log(yosay(`${chalk.blue("Nice to meet you!")}`));
}
console.log("Now that we have met, you can start conversation with me here β¬\n");
console.log(chalk.yellowBright("LinkedIn - ") + "https://www.linkedin.com/in/serjeel-ranjan/")
console.log(chalk.yellowBright("Twitter - ") + "https://twitter.com/r_serjeel/"+"\n");
console.log(chalk.greenBright("Visit my website - ") + "https://serjeel-ranjan.netlify.app/")
process.exit(0);
});
}
async function question1() {
console.clear();
console.log(yosay(`boo! π» ${chalk.blue("Spooky ")} question`));
const options = {
"I have met one": 10,
"Yes I am a believer": 9,
"I believe in paranormal activities": 8,
"No I am a scientific person": 6,
};
const answers = await inquirer.prompt({
name: "question_1",
type: "list",
message: `${chalk.bgRed("Do you believe in ghosts?")}\n`,
choices: Object.keys(options),
});
return handleAnswer(options[answers.question_1]);
}
async function question2() {
console.clear();
console.log(
yosay(`My season! and My ${chalk.blue("Coffee")}, π€ Best combination `)
);
const options = {
Spring: 7,
Summer: 10,
Winter: 5,
Fall: 6,
};
const answers = await inquirer.prompt({
name: "question_2",
type: "list",
message: `${chalk.bgRed("What's your favorite season?\n")}\n`,
choices: Object.keys(options),
});
return handleAnswer(options[answers.question_2]);
}
async function question3() {
console.clear();
console.log(yosay(`Take some break from πββ ${chalk.blue("Work")} β`));
const options = {
"Listening to music": 10,
"Going out": 9,
"Fooood!!!": 8,
Yoga: 7,
};
const answers = await inquirer.prompt({
name: "question_3",
type: "list",
message: `${chalk.bgRed("What is likely to be your stress buster?")}\n`,
choices: Object.keys(options),
});
return handleAnswer(options[answers.question_3]);
}
async function question4() {
console.clear();
console.log(yosay(`Wanna be ${chalk.blue("linguist")}? β`));
const options = {
Japanese: 8,
French: 7,
German: 6,
Russian: 7,
};
const answers = await inquirer.prompt({
name: "question_4",
type: "list",
message: `${chalk.bgRed("What foreign language you want to learn?")}\n`,
choices: Object.keys(options),
});
return handleAnswer(options[answers.question_4]);
}
async function question5() {
console.clear();
console.log(yosay(`Maybe / May not beβ`));
const options = {
"I already have one": 9,
"I want one": 8,
"I want but I can't": 6,
"Nope it's bad": 7,
};
const answers = await inquirer.prompt({
name: "question_5",
type: "list",
message: `${chalk.bgRed("Do you want a tattoo?")}\n`,
choices: Object.keys(options),
});
return handleAnswer(options[answers.question_5]);
}
async function question6() {
console.clear();
console.log(yosay(`${chalk.blue("Mind")} game for you`));
const answers = await inquirer.prompt({
name: "question_6",
type: "input",
message: `${chalk.bgRed(
"To which word you and add two letters to make it shorter?"
)}\n`,
default() {
return "";
},
});
return handleAnswer(answers.question_6.toUpperCase() === "SHORT" ? 10 : 6);
}
async function question7() {
console.clear();
console.log(yosay(`Lovely π ${chalk.blue("Childhood")}`));
const options = {
Astronaut: 9,
Teacher: 8,
Sportsman: 6,
Doctor: 7,
};
const answers = await inquirer.prompt({
name: "question_7",
type: "list",
message: `${chalk.bgRed(
"What likely you wanted to become in childhood?"
)}\n`,
choices: Object.keys(options),
});
return handleAnswer(options[answers.question_7]);
}
async function question8() {
console.clear();
console.log(yosay(`Nothing like π ${chalk.blue("home")}`));
const options = {
"New York": 9,
Tokyo: 8,
"Los Angeles": 8,
Amsterdam: 7,
Madrid: 7,
};
const answers = await inquirer.prompt({
name: "question_8",
type: "list",
message: `${chalk.bgRed("What city you want to live in?")}\n`,
choices: Object.keys(options),
});
return handleAnswer(options[answers.question_8]);
}
async function question9() {
console.clear();
console.log(yosay(`Another ${chalk.blue("mind")} game for you`));
const answers = await inquirer.prompt({
name: "question_9",
type: "input",
message: `${chalk.bgRed(
"What goes up and down, but always remains in the same place?"
)}\n`,
default() {
return "";
},
});
return handleAnswer(answers.question_9.toUpperCase() === "STAIRS" ? 10 : 6);
}
async function question10() {
console.clear();
console.log(yosay(`Interesting`));
const options = {
Yes: 9,
No: 9,
};
const answers = await inquirer.prompt({
name: "question_10",
type: "list",
message: `${chalk.bgRed("Ever been in relationship?\n")}\n`,
choices: Object.keys(options),
});
return handleAnswer(options[answers.question_10]);
}
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();
EndTheQuiz();