-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
87 lines (71 loc) · 2.27 KB
/
index.ts
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
#!/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 Person from './Person.js';
import Student from './Student.js';
const sleep = (ms = 2000) => new Promise((r) => setTimeout(r, ms));
async function welcome() {
console.log(gradient.pastel.multiline(figlet.textSync(`OOP Practice`, { horizontalLayout: 'full' })))
const rainbowTitle = chalkAnimation.rainbow(
`
Identify Your Personality Type \n
`
);
await sleep();
rainbowTitle.stop();
console.log(`
${chalk.bgBlue('HOW TO PLAY')}
I am a process on your computer.
${chalk.hex("#FF5733").bold('If you enjoy conversing with others, enter 1 and press enter.')}
${chalk.hex("#FFA500").bold('If you prefer to remain anonymous, enter 2 and press enter.')}
`);
}
await welcome()
function isNumber(str: string): boolean {
const possibly_a_number: number = parseInt(str);
const isNum: boolean = !isNaN(possibly_a_number);
return isNum;
}
async function userInputName() {
const userName = await inquirer.prompt({
type: "input",
name: "user_name",
message: "What is your name:"
})
if (userName.user_name) {
if (userName.user_name !== "") {
let studentName: string = userName["user_name"];
const student1: Student = new Student()
student1.Name = studentName
console.log(`Your name is ${student1.Name} and your personality is ${student1.getPersonality()}`)
} else {
console.log(chalk.red("Please enter a number"))
}
}
}
async function MainFn() {
try {
const answer = await inquirer.prompt({
name: 'select_a_number',
type: 'input',
message: chalk.blue("Type '1' if you like to talk to others or Type '2' If you prefer to remain anonymous:"),
});
if (answer.select_a_number !== "") {
const isNum: boolean = isNumber(answer["select_a_number"])
if (isNum) {
const person: Person = new Person()
person.askQuestion(answer["select_a_number"])
await userInputName()
}
else {
console.log(chalk.red("Please enter a number."))
}
}
} catch (error) {
console.log('Please enter a number.');
}
}
await MainFn()