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

pizza plz #149

Open
wants to merge 7 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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Project Name
# Project Pizza

This is an interactive site where you can order different types of food and portion sizes.

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.

## 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?
I did not have much time this week and I also found it very challenging to get started with JavaScript and understand how the syntax works. After we had the Labs session I started to understand it better, but by then I did not have time to change to code I had already put in here. I got a lot of help from Gemini. 0:-)

## 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://pizzaplz.netlify.app/
106 changes: 106 additions & 0 deletions code/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,120 @@ alert(
`Welcome to our Javascript Pizzeria. Ready to Start? - Click 'OK' to begin.`
)

let userName = prompt("What is your name?");
alert("Hi, " + userName + "!");

// Step 2 - Food choice
// Your code goes here
let foodChoices = ["Pizza", "Pasta", "Salad"];

let choice = prompt("Choose your food by entering a number (1, 2 or 3):\n1. Pizza\n2. Pasta\n3. Salad");

// Convert the choice to a number
choice = parseInt(choice);

// Check if the choice is valid and within the range of food choices
let chosenFood;
if (isNaN(choice) || choice < 1 || choice > foodChoices.length) {
alert("Invalid choice. Please enter a number between 1 and " + foodChoices.length);
} else {
chosenFood = foodChoices[choice - 1];
alert("You chose " + chosenFood);
}

// Declare chosenSubtype outside the switch statement
let chosenSubtype;

// Step 3 - Subtype choice
// Your code goes here
// Prompt for subtype only if chosenFood has subtypes
if (chosenFood === "Pizza" || chosenFood === "Pasta" || chosenFood === "Salad") {
let subtypes = {
Pizza: ["Pepperoni", "Margherita", "Hawaiian"],
Pasta: ["Spaghetti", "Mac and Cheese", "Lasagna"],
Salad: ["Caesar", "Greek", "Cobb"]
};

chosenSubtype = subtypes[chosenFood][parseInt(prompt(`Choose your ${chosenFood} type by entering a number (1, 2 or 3):\n1. ${subtypes[chosenFood][0]}\n2. ${subtypes[chosenFood][1]}\n3. ${subtypes[chosenFood][2]}`)) - 1];
}

// Step 4 - Age
// Your code goes here
// Step 4 - Child or adult
let age = parseInt(prompt("Enter the age of the person the food is for:"));

// Calculate the cost based on food type, subtype, and age
let foodPrices = {
Pizza: {
Pepperoni: {
adult: 100,
child: 80
},
Margherita: {
adult: 90,
child: 70
},
Hawaiian: {
adult: 110,
child: 90
}
},
Pasta: {
Spaghetti: {
adult: 80,
child: 60
},
"Mac and Cheese": {
adult: 70,
child: 50
},
Lasagna: {
adult: 90,
child: 70
}
},
Salad: {
Caesar: {
adult: 60,
child: 40
},
Greek: {
adult: 70,
child: 50
},
Cobb: {
adult: 80,
child: 60
}
}
};

// Construct the order message based on food type, subtype, and age
let orderMessage = `You ordered ${chosenFood}`;

if (chosenSubtype) {
orderMessage += ` - ${chosenSubtype}`;
}

if (age < 12) {
orderMessage += " (child portion)";
}

// Calculate the cost based on food type, subtype, and age
let cost = foodPrices[chosenFood][chosenSubtype][age < 12 ? "child" : "adult"];

// Display the order message and cost
alert(`Your order: ${orderMessage}\nTotal cost: ${cost} SEK`);



// Step 5 - Order confirmation
// Your code goes here
// Get confirmation
let confirmOrder = prompt("Confirm your order? (yes/no)");

if (confirmOrder.toLowerCase() === "yes") {
alert("Order confirmed!");
} else {
alert("Order canceled.");
}