-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
58 lines (51 loc) · 1.86 KB
/
index.ts
File metadata and controls
58 lines (51 loc) · 1.86 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
import inquirer from "inquirer";
class Student {
name: string;
constructor(n: string) {
this.name = n;
}
}
class Person {
students: Student[] = [];
addStudent(obj: Student) {
this.students.push(obj);
}
}
const persons = new Person();
const programStart = async (persons: Person) => {
console.log("Welcome!");
while (true) {
const ans = await inquirer.prompt({
name: 'select',
type: 'list',
message: 'Whom would you like to interact with?',
choices: ['staff', 'student', 'exit']
});
if (ans.select == 'staff') {
console.log('You approach the staff room. Please feel free to ask any question.');
} else if (ans.select == "student") {
const ansStudent = await inquirer.prompt({
name: "student",
type: "input",
message: "Enter the student's name you wish to engage with:"
});
const student = persons.students.find(val => val.name == ansStudent.student);
if (!student) {
const newStudent = new Student(ansStudent.student);
persons.addStudent(newStudent);
console.log(`Hello, I am ${newStudent.name}. Nice to meet you.`);
console.log("New student added.");
console.log("Current student list:");
console.log(persons.students);
} else {
console.log(`Hello, I am ${student.name}. Nice to see you again!`);
console.log("Existing student list:");
console.log(persons.students);
}
} else if (ans.select == "exit") {
console.log("Exiting the program!");
process.exit();
}
}
};
programStart(persons);