-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
148 lines (128 loc) · 3.12 KB
/
Copy pathindex.js
File metadata and controls
148 lines (128 loc) · 3.12 KB
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
#!/usr/bin/env node
import chalk from 'chalk';
import inquirer from 'inquirer';
import { createSpinner } from 'nanospinner';
import cowsay from 'cowsay';
let score = 0;
let name;
const wait = (ms = 1500) => new Promise((resolve) => setTimeout(resolve, ms));
console.log(chalk.blue(`
Hey there, I'm Pluto! welcome to my quiz.
`));
await wait();
await userName();
console.clear()
console.log(chalk.red(`
RULES
1. All of the questions are multiple choice
2. You will get your score at the end of the quiz
3. Have fun!
`));
await wait();
console.log(chalk.blue("Make sure you're ready, because the quiz is about to begin!"));
await wait();
async function userName() {
const nameAns = await inquirer.prompt({
name: "u_name",
type: "input",
message: "First off, we need to know your name!",
deafult() {
return 'User';
},
});
name = nameAns.u_name;
console.log(chalk.blue(`Hey ${name}. Let's get started!`));
}
let spinnerWords = [
"Trying to remember the answer...",
"Checking messages...",
"Thinking about cats...",
"Refreshing Twitter...",
"Wondering what's for dinner...",
]
let wordOut = spinnerWords[Math.floor(Math.random() * spinnerWords.length)];
let planets = [
'Mars',
'Earth',
'Venus',
'Mercury',
'Jupiter',
'Saturn',
'Uranus',
'Neptune',
'Pluto'
]
async function handleAnswer(correct) {
const spinner = createSpinner(wordOut).start();
await wait();
if (correct) {
score++;
spinner.success({ text: `GADZOOKS! That's right! I guess you humans are smarter than you seem...` });
} else {
spinner.error({ text: `Oh no, that's wrong! Better luck next time.` });
}
}
async function q0() {
const answers = await inquirer.prompt({
name: 'q0',
type: 'list',
message: '1. What is the name of the planet closest to the sun?',
choices: planets
});
return handleAnswer(answers.q0 === 'Mercury');
};
async function q1() {
const answers = await inquirer.prompt({
name: 'q1',
type: 'list',
message: '2. What is the smallest planet in our Solar System?',
choices: planets
});
return handleAnswer(answers.q1 === 'Pluto');
};
async function q2() {
const answers = await inquirer.prompt({
name: 'q2',
type: 'list',
message: '3. What country is NASA based in?',
choices: [
'Canada',
'America',
'China',
'India',
'England',
],
});
return handleAnswer(answers.q2 === 'America');
};
async function q3() {
const answers = await inquirer.prompt({
name: 'q3',
type: 'list',
message: '4. What is the hottest planet in our Solar System?',
choices: planets
});
return handleAnswer(answers.q3 === 'Venus');
};
async function q4() {
const answers = await inquirer.prompt({
name: 'q4',
type: 'list',
message: '5. What is the coldest planet in our Solar System?',
choices: planets
});
return handleAnswer(answers.q4 === 'Uranus');
};
async function end() {
console.log(chalk.blue(cowsay.say({
text : `CONGRATULATIONS, ${name}! your score was ${score}.`,
e: '^^',
T: 'U'
})));
};
await q0();
await q1();
await q2();
await q3();
await q4();
await end();