diff --git a/README.md b/README.md index 33c7e601..eed7124b 100644 --- a/README.md +++ b/README.md @@ -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. + +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 diff --git a/code/readme b/code/readme new file mode 100644 index 00000000..e69de29b diff --git a/code/script.js b/code/script.js index 34ca0f34..14a02893 100644 --- a/code/script.js +++ b/code/script.js @@ -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.` + `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.` ) // 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 + 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) { + 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") { + 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 -// 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") + } +}