-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
106 lines (106 loc) · 3.79 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
#! /usr/bin/env node
//shabang
import inquirer from "inquirer";
import chalk from "chalk";
// console.log(chalkAnimation.);
class student {
id;
name;
coursesEnrolled;
feesAmount;
constructor(id, name, coursesEnrolled, feesAmount) {
this.id = id;
this.name = name;
this.coursesEnrolled = coursesEnrolled;
this.feesAmount = feesAmount;
}
}
let baseId = 10000;
let studentId = "";
let continueEnrollment = true;
let students = [];
do {
let action = await inquirer.prompt({
type: "list",
name: "ans",
message: chalk.red("Please select an option: \n "),
choices: ["Enroll a student", "Show student status"]
});
if (action.ans === "Enroll a student") {
let studentName = await inquirer.prompt({
type: "input",
name: "ans",
message: chalk.green("Please enter your name:")
});
let trimedStudentName = (studentName.ans).trim().toLowerCase();
let studentNameCheck = students.map(obj => obj.name);
if (studentNameCheck.includes(trimedStudentName) === false) {
if (trimedStudentName !== "") {
baseId++;
studentId = "STID" + baseId;
console.log(chalk.yellow.bold("\n\tYour account has been created"));
console.log(`Welcome`, `${trimedStudentName}!`);
let course = await inquirer.prompt({
type: "list",
name: "ans",
message: (chalk.bgBlue("Please select a course:")),
choices: ["IT", "English", "Scince"]
});
let courseFees = 0;
switch (course.ans) {
case "IT":
courseFees = 5000;
break;
case "English":
courseFees = 1000;
break;
case "Science":
courseFees = 1500;
break;
}
let courseConfirm = await inquirer.prompt({
type: "confirm",
name: "ans",
message: chalk.cyan("Do you want to enroll in this course ?")
});
if (courseConfirm.ans === true) {
let Student = new student(studentId, trimedStudentName, [course.ans], courseFees);
students.push(Student);
console.log(chalk.yellow.bold(`\n\tYou have enrolled in this course!`));
}
}
else {
console.log("Invalid Name");
}
}
else {
console.log(chalk.magenta("This name is already exists"));
}
}
else if (action.ans === "Show student status") {
if (students.length !== 0) {
let studentNamesCheck = students.map(e => e.name);
let selectedStudent = await inquirer.prompt({
type: "list",
name: "ans",
message: "Please select name",
choices: studentNamesCheck
});
let foundStudent = students.find(Student => Student.name === selectedStudent.ans);
console.log("Student Information");
console.log(foundStudent);
console.log("\n");
}
else {
console.log(chalk.magenta("Record is empty!"));
}
}
let userConfirm = await inquirer.prompt({
type: "confirm",
name: "ans",
message: chalk.red("Do you want to continue ?")
});
if (userConfirm.ans === false) {
continueEnrollment = false;
}
} while (continueEnrollment);