-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
142 lines (140 loc) · 3.71 KB
/
app.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
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
const employeeList = [
{
name: "Jan",
officeNum: 1,
phoneNum: "222-222-2222"
},
{
name: "Juan",
officeNum: 304,
phoneNum: "489-789-8789"
},
{
name: "Margie",
officeNum: 789,
phoneNum: "789-789-7897"
},
{
name: "Sara",
officeNum: 32,
phoneNum: "222-789-4654"
},
{
name: "Tyrell",
officeNum: 3,
phoneNum: "566-621-0452"
},
{
name: "Tasha",
officeNum: 213,
phoneNum: "789-766-5675"
},
{
name: "Ty",
officeNum: 211,
phoneNum: "789-766-7865"
},
{
name: "Sarah",
officeNum: 345,
phoneNum: "222-789-5231"
}
];
const command = prompt("Enter a command");
if (command === "print") {
for (let i = 0; i < employeeList.length; i++) {
render(employeeList[i].name);
render(employeeList[i].officeNum);
render(employeeList[i].phoneNum);
}
} else if (command === "verify") {
const inputName = prompt("Enter an employee's name");
let count = 0;
for (let i = 0; i < employeeList.length; i++) {
if (employeeList[i].name === inputName) {
count++;
}
}
render(count === 1);
} else if (command === "lookup") {
const inputName = prompt("Enter an employee's name");
let index = 0;
for (let i = 0; i < employeeList.length; i++) {
if (employeeList[i].name === inputName) {
index = i;
}
}
render(employeeList[index].name);
render(employeeList[index].officeNum);
render(employeeList[index].phoneNum);
} else if (command === "contains") {
const inputStr = prompt("Enter keyword");
for (let i = 0; i < employeeList.length; i++) {
if (employeeList[i].name.includes(inputStr)) {
render(employeeList[i].name);
render(employeeList[i].officeNum);
render(employeeList[i].phoneNum);
}
}
} else if (command === "update") {
const inputName = prompt("Enter an employee's name");
const inputField = prompt("Enter a field");
const inputValue = prompt("Enter a value");
for (let i = 0; i < employeeList.length; i++) {
if (employeeList[i].name === inputName) {
index = i;
}
}
employeeList[index][inputField] = inputValue;
render(employeeList[index].name);
render(employeeList[index].officeNum);
render(employeeList[index].phoneNum);
} else if (command === "add") {
const inputName = prompt("Enter an employee's name");
const inputOffice = prompt("Enter office number");
const inputPhone = prompt("Enter telephone number");
leng = employeeList.length;
newObj = [];
employeeList.push(newObj);
newObj.name = inputName;
newObj.officeNum = inputOffice;
newObj.phoneNum = inputPhone;
for (let i = 0; i < employeeList.length; i++) {
render(employeeList[i].name);
render(employeeList[i].officeNum);
render(employeeList[i].phoneNum);
}
} else if (command === "delete") {
const inputName = prompt("Enter an employee's name");
for (let i = 0; i < employeeList.length; i++) {
if (employeeList[i].name === inputName) {
index = i;
}
}
employeeList[index] = [];
for (let i = 0; i < employeeList.length; i++) {
render(employeeList[i].name);
render(employeeList[i].officeNum);
render(employeeList[i].phoneNum);
}
} else if (command === "location") {
const inputName = prompt("Enter an employee's name");
for (let i = 0; i < employeeList.length; i++) {
if (employeeList[i].name === inputName) {
index = i;
}
}
office = parseInt(employeeList[index].officeNum);
leng = office.toString().length;
if (leng <= 2) {
render(`${inputName} is located on the ground floor in office ${office}.`);
} else if (leng === 3) {
render(
`${inputName} is located on floor ${
office.toString()[0]
} in office ${office}.`
);
} else {
render("Not a valid command. Refresh the page.");
}
}