Skip to content
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

Week 4: Pizzabot #139

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Project Name

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.
This project is a small introduction to a JavaScript language. This Pizzeria Ordering System is an interactive web-based application that guides "clients" through customising their food order. It prompts users to input their name, choose between pizza, pasta, or salad, and select specific dish types like Margherita or Caesar Salad. The system also requests the user's age to determine whether to prepare a child-sized or adult-sized portion, then asks for final order confirmation using "Yes" or "No." The project demonstrates basic JavaScript functions, input handling, and conditional logic.

## 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?
To implement the system, I used vanilla JavaScript, focusing on the use of prompt() and alert() for user interaction. The logic was built using functions and conditional statements (such as if/else) to control the flow based on user inputs. I structured the project around functions to modularise different tasks like selecting food type and confirming the order, ensuring the program remained organised and easy to follow (which was A struggle).
If I had more time, I would enhance the project by adding error handling for invalid inputs, refining the UI to replace the basic prompt() and alert() boxes with more visually appealing forms, and perhaps implementing a responsive design using HTML and CSS.

## 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
https://pizzzabot.netlify.app
Binary file added code/Screenshot 2024-09-03 at 11.17.59.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
/>
</head>
<body>
<h1>Javascript Pizzeria</h1>
<p>Logic is executed automatically</p>
<script src="./script.js"></script>
<div class="header">
<h1>Javascript Pizzeria</h1>
<p>Logic is executed automatically</p>
</div>
<img src="Screenshot 2024-09-03 at 11.17.59.png" alt="PizzaBot" width="400">
</body>
<script src="./script.js"></script>
</html>
140 changes: 126 additions & 14 deletions code/script.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,131 @@
// Start here

// Step 1 - Welcome and introduction
// Your code goes here
alert(
`Welcome to our Javascript Pizzeria. Ready to Start? - Click 'OK' to begin.`
)
alert("Welcome to our Javascript Pizzeria. Ready to Start? - Click 'OK' to begin.");

// Ask for the user's name and store the answer in a variable
const userName = prompt("Please insert your name for the Pizzeria to remember your order :)");

// Greet the user with their name
alert("Hi, " + userName + "! Thanks for taking an order from our Javascript Pizzeria.");

// Declare variables for foodType and chosenSubtype globally


// Step 2 - activating the choosingFood function
choosingFood();

// Function to ask for food type
function QuestionFoodtype() {
const foodChoice = prompt("Please let us know which type of dish you would like to order. Please write a number:\n1 - Pizza\n2 - Pasta \n3 - Salad");
return parseInt(foodChoice);
}

//for the function to loop properly I have built 2 separate functions - one for the question, where the client orders the number from the menu and - second for the process of the answers, whether the client has inserted a correct menu number or not - thus looping the function
function choosingFood() {
foodType = QuestionFoodtype();

if (foodType === 1) {
foodTypeName = "Pizza";
alert("Great, thank you! You've chosen a Pizza!");
}
else if (foodType === 2) {
foodTypeName = "Pasta";
alert("Great, thank you! You've chosen a Pasta!");
}
else if (foodType === 3) {
foodTypeName = "Salad";
alert("Great, thank you! You've chosen a Salad!");
}
else {
alert("Unfortunately, we don't have that type of dish, please try again!");
choosingFood();
Comment on lines +39 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice ⭐

return;
}

QuestionSubFoodType(foodType);
}

//at this point of process, we know what type of menu item the client has chosen
//Step 3 - now asking the type of dish
function QuestionSubFoodType(foodType) {
let subtype;

if (foodType === 1) {
subtype = prompt("What type of pizza would you like?\n1 - Margharita\n2 - Pepperoni\n3 - Hawaiian");
}
else if (foodType === 2) {
subtype = prompt("What type of pasta would you like?\n1 - Bolognese\n2 - Crema di pollo\n3 - Pesto");
}
else if (foodType === 3) {
subtype = prompt("What type of salad would you like?\n1 - Caesar\n2 - Greek\n3 - Mozzarella");
}

//from this point, we now know everything the client has chosen from the menu - the food dish and the type of dish
if (foodType === 1) {
if (subtype === "1") {
chosenSubtype = "Margharita";
}
else if (subtype === "2") {
chosenSubtype = "Pepperoni";
}
else if (subtype === "3") {
chosenSubtype = "Hawaiian";
}
else {
alert("Unfortunately, we do not have that item on the menu, try again.");
QuestionSubFoodType(foodType);
return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!!

}
}
else if (foodType === 2) {
if (subtype === "1") {
chosenSubtype = "Bolognese";
}
else if (subtype === "2") {
chosenSubtype = "Crema di pollo";
}
else if (subtype === "3") {
chosenSubtype = "Pesto";
}
else {
alert("Unfortunately, we do not have that item on the menu, try again.");
QuestionSubFoodType(foodType);
return;
}
}
else if (foodType === 3) {
if (subtype === "1") {
chosenSubtype = "Caesar";
}
else if (subtype === "2") {
chosenSubtype = "Greek";
}
else if (subtype === "3") {
chosenSubtype = "Mozzarella";
}
else {
alert("Unfortunately, we do not have that item on the menu, try again.");
QuestionSubFoodType(foodType);
return;
}
}

alert("You have chosen " + chosenSubtype + ". Thank you, " + userName + "!");
}

// Step 2 - Food choice
// Your code goes here
//Now I have gotten to a point of where the client has made fully their order - final alert with the suborder and name
//Step 4 - now asking the client's age

// Step 3 - Subtype choice
// Your code goes here
let age = parseInt(prompt("Can you also tell us your age in numbers, so we know whether we can prepare the order for an adult or a child?"));

// Step 4 - Age
// Your code goes here
if (age <= 18) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nicely done!! I used a "child" or "adult" in strings but this is a cleaner way.

confirmation = prompt("Thank you for the info! One child-size, " + foodTypeName + " " + chosenSubtype + " coming right up. That'll be €10. Are you sure you want to order this? \nPlease confirm: \nyes \nno");
} else {
confirmation = prompt("Thank you for the info! One adult-size, " + foodTypeName + " " + chosenSubtype + " coming right up. That'll be €15. Are you sure you want to order this? \nPlease confirm: \nYes \nNo");
}

// Step 5 - Order confirmation
// Your code goes here
//Step 5 - the last stretch with the confirmation code
if (confirmation.toLowerCase() === "yes") {
alert("Thank you for your order, my friend! That will take around 10 minutes.");
} else if (confirmation.toLowerCase() === "no") {
alert("Alrighty! See you next time!");
}
17 changes: 16 additions & 1 deletion code/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

body {
font-family: "Montserrat", sans-serif;
background: #0026ff;
background: #221213;
color: white;
display: flex;
justify-content: center;
Expand All @@ -15,6 +15,21 @@ body {
min-height: 100vh;
}

.header {
text-align: center;
margin-top: 200px;
}

.header h1 {
margin: 0;
font-size: 2.5em;
}

.header p {
margin: 0;
font-size: 1.2em;
}

p {
font-size: 1.5em;
}