Skip to content

Commit 7ca9685

Browse files
authored
Lighter JS
1 parent a66d4cd commit 7ca9685

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

app.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const employeeList = [
4242
}
4343
];
4444

45-
//Functions
45+
//Functions
4646

4747
const inputCommand = prompt('Enter Command');
4848
const commandList = ['print', 'verify', 'lookup', 'contains', 'update', 'add', 'delete'];
@@ -71,6 +71,14 @@ for (let i = 0; i < commandList.length; i++) {
7171
update();
7272
}
7373

74+
else if (inputCommand === commandList[5]) {
75+
addEmp();
76+
}
77+
78+
else if (inputCommand === commandList[6]) {
79+
deleteEmp();
80+
}
81+
7482
};
7583

7684
//Print
@@ -149,4 +157,31 @@ function update() {
149157
}
150158
}
151159

160+
//Add
161+
162+
function addEmp() {
163+
const nameAdd = prompt('Enter Employee Name');
164+
const officeAdd = prompt('Enter Office Number');
165+
const phoneAdd = prompt('Enter Phone Number');
166+
var employeeAdd = { name: nameAdd, officeNum: officeAdd, phoneNum: phoneAdd };
167+
employeeList.push(employeeAdd);
168+
render(`${nameAdd} has been added.`);
169+
render(`-------------------------------------------------------`);
170+
print();
171+
}
172+
173+
//Delete
174+
175+
function deleteEmp() {
176+
const nameDelete = prompt('Enter Employee Name').toLowerCase();
177+
for (i = 0; i < employeeList.length; i++) {
178+
if (nameDelete === employeeList[i].name.toLowerCase()) {
179+
employeeList.splice(i, 1);
180+
}
181+
}
182+
render(`${nameQuery} has been successfully removed from employee list!`);
183+
render(`-------------------------------------------------------`);
184+
print()
185+
}
186+
152187

0 commit comments

Comments
 (0)