-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Project Pizzeria Fresco! #140
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
# Project Name | ||
Project: Pizzeria Fresco! | ||
|
||
Replace this readme with your own information about your project. Start by briefly describing the assignment in a sentence or two. Keep it short and to the point. | ||
Pizzeria Fresco is ment to be; an interactive JavaScript-based bot that takes a user's order at a virtual pizzeria. It starts by greeting the user, asking for their name, and guiding them through choosing a dish from the menu. The bot also collects the user's age and provides an order confirmation. | ||
|
||
## The problem | ||
The Problem | ||
|
||
Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next? | ||
The primary challenges in this project were: | ||
|
||
Properly handerling the Variables: Structuring the code to ensure variables were introduced at the correct time. | ||
|
||
Initially, a lot of variables (like foodType or pizzaType) were embedded within conditional blocks (such as if statements), which led to scope issues. To fix this, I restructured the code so that these variables were declared in the right order. | ||
|
||
Ensuring User Input Validation: | ||
The goal was to continuously prompt the user until they provided a valid input. This was achieved using a while (true) loop, which only breaks when the user selects a valid option. If an invalid option is selected, the loop will prompt the user again. | ||
|
||
If given more time, I would: | ||
|
||
- Refactor the code: To clean it up further by breaking parts of the code into functions for better readability and maintainability. | ||
- Extend Functionality: Allow more complex customizations, such as toppings for pizzas or dressings for salads. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤩 |
||
|
||
View it Live: | ||
Deployed Project: https://main--pizzeriafresco.netlify.app | ||
|
||
## View it live | ||
|
||
Have you deployed your project somewhere? Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,198 @@ | ||
// Start here | ||
|
||
// Step 1 - Welcome and introduction | ||
// Your code goes here | ||
alert( | ||
`Welcome to our Javascript Pizzeria. Ready to Start? - Click 'OK' to begin.` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn’t seem to affect anything, but I noticed two alerts in one call. |
||
`Hey there, pizza lover! 🍕 Welcome to Pizzeria Fresco! Click 'OK' to get started!` | ||
) | ||
const userName = prompt(`What is your name?`) | ||
console.log("User's name is:", userName) | ||
|
||
alert( | ||
`Hi there, ${userName}! 😊 It's great to meet you. Click 'OK' to start placing your order.` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice with the emojis! 😃 |
||
) | ||
|
||
// Step 2 - Food choice | ||
// Your code goes here | ||
// Selection between Pizza, Pasta, Salad | ||
// while loop to ensure that the user selects a valid option if not, the user will be prompted to select again. Will loop until it hits break. | ||
let foodType | ||
|
||
while (true) { | ||
|
||
let foodSelection = prompt(`Please select your food of choice: | ||
Write: 1 - for Pizza 🍕 | ||
Write: 2 - for Pasta 🍝 | ||
Write: 3 - for Salad 🥗`) | ||
|
||
// convert the variabel "foodSelection" to be a number instead of a string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job converting the user input to a number. That made your conditional statement cleaner, and ensures that the comparison works as expected. |
||
foodSelection = Number(foodSelection) | ||
|
||
|
||
if (foodSelection === 1) { | ||
console.log("Pizza") | ||
foodType = "Pizza" | ||
break | ||
} else if (foodSelection === 2) { | ||
console.log("Pasta") | ||
foodType = "Pasta" | ||
break | ||
} else if (foodSelection === 3) { | ||
console.log("Salad") | ||
foodType = "Salad" | ||
break | ||
} else { | ||
alert( | ||
`Oops! It looks like that's not an option. Please choose from 1, 2, or 3` | ||
) | ||
console.log("Invalid selection. Please choose 1, 2, or 3.") | ||
} | ||
} | ||
//message with the food that has been chosen | ||
alert(`Great choice, ${foodType}! Click 'OK' to select the specific type of ${foodType} you'd like.`) | ||
|
||
// Step 3 - Subtype choice | ||
// Your code goes here | ||
// Variables to store subtype choices | ||
let pizzaType | ||
let pastaType | ||
let saladType | ||
let subType | ||
|
||
//If choice is Pizza -> select type of pizza | ||
if (foodType === "Pizza") { | ||
while (true) { | ||
pizzaType = prompt(`Please select your type of Pizza 🍕: | ||
Write: 1 - for Margherita Pizza | ||
Write: 2 - for Pepperoni Pizza | ||
Write: 3 - for Veggie Pizza` | ||
) | ||
|
||
pizzaType = Number(pizzaType) | ||
|
||
if (pizzaType === 1) { | ||
console.log("Margherita") | ||
subType = "Margherita Pizza" | ||
break | ||
} else if (pizzaType === 2) { | ||
console.log("Pepperoni Pizza") | ||
subType = "Pepperoni" | ||
break | ||
} else if (pizzaType === 3) { | ||
console.log("Veggie") | ||
subType = "Veggie Pizza" | ||
break | ||
} else { | ||
alert(`Oops! It looks like that's not an option. Please choose from 1, 2, or 3`) | ||
console.log("Invalid selection. Please choose 1, 2, or 3.") | ||
} | ||
} | ||
} | ||
|
||
|
||
// If choice is pasta -> select type of pasta | ||
if (foodType === "Pasta") { | ||
while (true) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice error handling with the loop. |
||
pastaType = prompt(`Please select your type of Pasta 🍝: | ||
Write: 1 - for Spaghetti Carbonara | ||
Write: 2 - for Spaghetti Bolognese | ||
Write: 3 - for Pasta Primavera` | ||
) | ||
|
||
pastaType = Number(pastaType) | ||
|
||
if (pastaType === 1) { | ||
console.log("Carbonara") | ||
subType = "Spaghetti Carbonara" | ||
break | ||
} else if (pastaType === 2) { | ||
console.log("Bolognese") | ||
subType = "Spaghetti Bolognese" | ||
break | ||
} else if (pastaType === 3) { | ||
console.log("Primavera") | ||
subType = "Pasta Primavera" | ||
break | ||
} else { | ||
alert(`Oops! It looks like that's not an option. Please choose from 1, 2, or 3`) | ||
console.log("Invalid selection. Please choose 1, 2, or 3.") | ||
} | ||
} | ||
} | ||
|
||
// If choice is salad -> select type of salad | ||
if (foodType === "Salad") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kudos for using the camelCase format throughout the whole code. |
||
while (true) { | ||
saladType = prompt(`Please select your type of Salad 🥗: | ||
Write: 1 - for Ceacar Salad | ||
Write: 2 - for Shrimp Salad | ||
Write: 3 - for Greek Salad` | ||
) | ||
|
||
saladType = Number(saladType) | ||
|
||
if (saladType === 1) { | ||
console.log("Ceacar Salad") | ||
subType = "Ceacar Salad" | ||
break | ||
} else if (saladType === 2) { | ||
console.log("Shrimp Salad") | ||
subType = "Shrimp Salad" | ||
break | ||
} else if (saladType === 3) { | ||
console.log("Greek Salad") | ||
subType = "Greek Salad" | ||
break | ||
} else { | ||
alert(`Oops! It looks like that's not an option. Please choose from 1, 2, or 3`) | ||
console.log("Invalid selection. Please choose 1, 2, or 3.") | ||
} | ||
} | ||
} | ||
//message with the subtype that has been chosen | ||
alert(`Yum! You've selected ${subType}! Excellent choice! Click 'OK' to start placing your order.`) | ||
|
||
|
||
// Step 4 - Age | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Smart to use the two options adult or child instead of age (integer). It made the response better, and the code cleaner. |
||
// Your code goes here | ||
let userAge; | ||
while (true) { | ||
userAge = prompt( | ||
`Is this order intended for a child or an adult? Please respond with 'adult' or 'child' in the field below:` | ||
) | ||
console.log("User's age is:", userAge) | ||
|
||
if (userAge === "adult" || userAge === "child") { | ||
break | ||
} else { | ||
alert( | ||
`Oops! It looks like that's not an option. Please choose 'adult' or 'child'` | ||
) | ||
console.log("Invalid selection. Please choose:", "child", "adult") | ||
} | ||
} | ||
|
||
let confirmation; | ||
while (true) { | ||
if (userAge === "adult") { | ||
confirmation = | ||
prompt( | ||
`One Adult-sized ${subType} coming straight up!🍕 | ||
Do you accept? | ||
Please enter 'yes' to confirm or 'no' to decline:`) | ||
} else if (userAge === "child") { | ||
confirmation = prompt( | ||
`One Child-sized ${subType} coming straight up! 🍕 | ||
Do you accept? | ||
Please enter 'yes' to confirm or 'no' to decline:`) | ||
} | ||
|
||
// Step 5 - Order confirmation | ||
// Your code goes here | ||
// Step 5 - Order confirmation | ||
if (confirmation === "yes") { | ||
alert( | ||
`Woho! 🎉 Your ${subType} is on its way! Thanks for dining with us at Pizzeria Fresco! 🍕` | ||
); | ||
break | ||
} else if (confirmation === "no") { | ||
alert(`Your order has been cancelled. Hope to see you here again soon!`) | ||
break | ||
} else { | ||
alert(`Invalid selection. Please choose 'yes' or 'no'.`) | ||
console.log("Invalid selection. Please choose:", "yes", "no") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐