-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek5-Menu-App.js
More file actions
70 lines (62 loc) · 1.74 KB
/
Week5-Menu-App.js
File metadata and controls
70 lines (62 loc) · 1.74 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
59
60
61
62
63
64
65
66
67
68
69
70
class Order {
constructor(food) {
this.food = food;
}
describe() {
return `In your order: ${this.food}.`;
}
}
class Menu {
constructor() {
//set up initial data
this.items = []; //array of items
this.selectedItem = null;
}
start() {
let selection = this.showMenuOptions();
while(selection != 0) {
switch (selection) {
case "1":
this.startOrder();
break;
case "2":
this.viewOrder();
break;
case "3":
this.deleteOrder();
break;
default:
selection = 0;
}
selection = this.showMenuOptions();
}
alert("Thank you, come again!");
}
showMenuOptions() {
return prompt(`Welcome to the cafe!
0. Leave
1. Add to order
2. View order
3. Remove items
`);
}
startOrder() {
let food = prompt('What would you like?');
this.items.push(new Order(food));
}
viewOrder() {
let orderString = '';
for (let i = 0; i < this.items.length; i++) {
orderString += i + '. ' + this.items[i].food + '\n';
}
alert('In your order:' + '\n\n' + orderString);
}
deleteOrder() {
let index = prompt('Enter the index of the item to remove:');
if (index > -1 && index < this.items.length) {
this.items.splice(index, 1);
}
}
}
const menu = new Menu()
menu.start()