forked from Technigo/project-pizza
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
124 lines (105 loc) · 3.31 KB
/
script.js
File metadata and controls
124 lines (105 loc) · 3.31 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
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
// Step 1 - Welcome and introduction
alert(
`Welcome to our Javascript Pizzeria. Ready to Start? - Click 'OK' to begin.`
);
// b) user's name using the prompt
let name = prompt("What is your name?");
// c) alert using the name variable to greet the user
alert(
`Hi, ${name}!`
);
// Step 2 - Food choice
let choice = prompt("What food would you like to order?\n1. Pizza\n2. Pasta\n3. Salad\nEnter a number:");
let foodType;
if (choice === "1") {
foodType = "Pizza";
} else if (choice === "2") {
foodType = "Pasta";
} else if (choice === "3") {
foodType = "Salad";
} else {
foodType = null;
}
//alert message for choice of food
if (foodType) {
alert(`You have selected ${foodType}.`);
} else {
alert("Invalid choice. Please try again.");
}
// Step 3 - Subtype choice
let subtype;
// Pizza subtypes
if (foodType === "Pizza") {
subtype = prompt("Please choose a Pizza type:\n1. Margherita\n2. Capricciosa\n3. Marinara\nPlease enter a number:");
if (subtype === "1") {
subtype = "Margherita";
} else if (subtype === "2") {
subtype = "Capricciosa";
} else if (subtype === "3") {
subtype = "Marinara";
//alert message for subtype of pizza
} else {
alert("Invalid choice. Please refresh and try again.");
}
alert(`You have selected ${subtype}.`);
}
// Pasta subtypes
else if (foodType === "Pasta") {
subtype = prompt("Please choose a Pasta type:\n1. Carbonara\n2. Arrabiata\n3. Bolognese\nPlease enter a number:");
if (subtype === "1") {
subtype = "Carbonara";
} else if (subtype === "2") {
subtype = "Arrabiata";
} else if (subtype === "3") {
subtype = "Bolognese";
//alert message for subtype of pasta
} else {
alert("Invalid choice. Please refresh and try again.");
}
if (subtype) {
alert(`You have selected ${subtype}.`);
}
}
// Salad subtypes
else if (foodType === "Salad") {
subtype = prompt("Please choose a Salad type:\n1. Greek salad\n2. Salad Nicoise \n3. Caesar salad\nPlease enter a number:");
if (subtype === "1") {
subtype = "Greek salad";
} else if (subtype === "2") {
subtype = "Salad Nicoise";
} else if (subtype === "3") {
subtype = "Caesar salad";
}
//alert message for subtype of salad
alert(`You have selected ${subtype}.`);
} else {
alert("Invalid choice. Please refresh and try again.");
}
// Step 4 - Age
let age = prompt("Is this food for a child or an adult? Please type your age:");
let ageGroup, cost;
if (age < 16) {
ageGroup = "Child";
cost = "€8.00";
} else if (age >= 16) {
ageGroup = "Adult";
cost = "€10.00";
//alert message for age and cost
} else {
alert("Invalid age entered. Please try again.");
}
if (ageGroup && cost) {
alert(`You have selected food for a ${ageGroup}. The cost will be ${cost}.`);
}
// Step 5 - Order confirmation
if (ageGroup && foodType && subtype) {
let orderDetails = `You are about to order a ${foodType} (${subtype}) for a ${ageGroup}. The cost will be ${cost}. Would you like to confirm your order?`;
let confirmation = prompt(`${orderDetails}\n1. Yes\n2. No\nPlease enter a number:`);
if (confirmation === "1") {
alert("Thank you! Your meal will be prepared shortly.");
} else if (confirmation === "2") {
alert("Thank you for visiting! We hope to see you again soon.");
} else {
alert("Invalid choice. Please refresh the page and try again.");
}
}