From dc392b3fb0248f6dc498bdda564b6f4e925cbf45 Mon Sep 17 00:00:00 2001 From: Nella Edvardsson Date: Mon, 2 Sep 2024 11:10:04 +0200 Subject: [PATCH 1/7] userName --- code/script.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/script.js b/code/script.js index 34ca0f34..247b4400 100644 --- a/code/script.js +++ b/code/script.js @@ -6,6 +6,9 @@ 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 From 1b972fcc11a5c9ba7083205dd38d3caeb82eebb0 Mon Sep 17 00:00:00 2001 From: Nella Edvardsson Date: Mon, 2 Sep 2024 11:44:29 +0200 Subject: [PATCH 2/7] foodChoices --- code/script.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/code/script.js b/code/script.js index 247b4400..105e6818 100644 --- a/code/script.js +++ b/code/script.js @@ -11,7 +11,26 @@ alert("Hi, " + userName + "!"); // Step 2 - Food choice // Your code goes here +let foodChoices = ["Pizza", "Pasta", "Salad"]; +let choice = prompt("Choose your food: Pizza, Pasta, or Salad"); + +// Convert the choice to lowercase for case-insensitive comparison +choice = choice.toLowerCase(); + +switch (choice) { + case "pizza": + alert("You chose Pizza"); + break; + case "pasta": + alert("You chose Pasta"); + break; + case "salad": + alert("You chose Salad"); + break; + default: + alert("Invalid choice. Please enter Pizza, Pasta, or Salad."); +} // Step 3 - Subtype choice // Your code goes here From 42b50fd98d13c3e52bb58e2c4509b2ef47545146 Mon Sep 17 00:00:00 2001 From: Nella Edvardsson Date: Tue, 3 Sep 2024 08:44:09 +0200 Subject: [PATCH 3/7] foodChoice 1 2 3 --- code/script.js | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/code/script.js b/code/script.js index 105e6818..4d436592 100644 --- a/code/script.js +++ b/code/script.js @@ -13,24 +13,19 @@ alert("Hi, " + userName + "!"); // Your code goes here let foodChoices = ["Pizza", "Pasta", "Salad"]; -let choice = prompt("Choose your food: Pizza, Pasta, or Salad"); - -// Convert the choice to lowercase for case-insensitive comparison -choice = choice.toLowerCase(); - -switch (choice) { - case "pizza": - alert("You chose Pizza"); - break; - case "pasta": - alert("You chose Pasta"); - break; - case "salad": - alert("You chose Salad"); - break; - default: - alert("Invalid choice. Please enter Pizza, Pasta, or 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 +if (isNaN(choice) || choice < 1 || choice > foodChoices.length) { + alert("Invalid choice. Please enter a number between 1 and " + foodChoices.length); +} else { + let chosenFood = foodChoices[choice - 1]; + alert("You chose " + chosenFood); } + // Step 3 - Subtype choice // Your code goes here From 3fa637bcf786a1d1557a2e5f6259790f6ec8c22d Mon Sep 17 00:00:00 2001 From: Nella Edvardsson Date: Tue, 3 Sep 2024 08:51:59 +0200 Subject: [PATCH 4/7] food types --- code/script.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/code/script.js b/code/script.js index 4d436592..78c00a2b 100644 --- a/code/script.js +++ b/code/script.js @@ -19,15 +19,38 @@ let choice = prompt("Choose your food by entering a number (1, 2 or 3):\n1. Pizz 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 { - let chosenFood = foodChoices[choice - 1]; + chosenFood = foodChoices[choice - 1]; alert("You chose " + chosenFood); } + // Step 3 - Subtype choice // Your code goes here +// Prompt for subtype based on chosen food +switch (chosenFood) { + case "Pizza": + let pizzaTypes = ["Pepperoni", "Margherita", "Hawaiian"]; + let pizzaChoice = prompt("Choose your pizza type by entering a number (1, 2 or 3):\n1. Pepperoni\n2. Margherita\n3. Hawaiian"); + // ... handle pizza subtype choice + break; + case "Pasta": + let pastaTypes = ["Spaghetti", "Mac and Cheese", "Lasagna"]; + let pastaChoice = prompt("Choose your pasta type by entering a number (1, 2 or 3):\n1. Spaghetti\n2. Mac and Cheese\n3. Lasagna"); + // ... handle pasta subtype choice + break; + case "Salad": + let saladTypes = ["Caesar", "Greek", "Cobb"]; + let saladChoice = prompt("Choose your salad type by entering a number (1, 2 or 3):\n1. Caesar\n2. Greek\n3. Cobb"); + // ... handle salad subtype choice + break; + default: + alert("Error: Invalid food choice."); +} + // Step 4 - Age // Your code goes here From 41cdfec6fb0fe91cfc685bb6a91c5d4c805d7ee5 Mon Sep 17 00:00:00 2001 From: Nella Edvardsson Date: Tue, 3 Sep 2024 09:54:18 +0200 Subject: [PATCH 5/7] steps 1-5 --- code/script.js | 106 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 20 deletions(-) diff --git a/code/script.js b/code/script.js index 78c00a2b..cf664e9a 100644 --- a/code/script.js +++ b/code/script.js @@ -27,33 +27,99 @@ if (isNaN(choice) || choice < 1 || choice > foodChoices.length) { alert("You chose " + chosenFood); } +// Declare chosenSubtype outside the switch statement +let chosenSubtype; // Step 3 - Subtype choice // Your code goes here -// Prompt for subtype based on chosen food -switch (chosenFood) { - case "Pizza": - let pizzaTypes = ["Pepperoni", "Margherita", "Hawaiian"]; - let pizzaChoice = prompt("Choose your pizza type by entering a number (1, 2 or 3):\n1. Pepperoni\n2. Margherita\n3. Hawaiian"); - // ... handle pizza subtype choice - break; - case "Pasta": - let pastaTypes = ["Spaghetti", "Mac and Cheese", "Lasagna"]; - let pastaChoice = prompt("Choose your pasta type by entering a number (1, 2 or 3):\n1. Spaghetti\n2. Mac and Cheese\n3. Lasagna"); - // ... handle pasta subtype choice - break; - case "Salad": - let saladTypes = ["Caesar", "Greek", "Cobb"]; - let saladChoice = prompt("Choose your salad type by entering a number (1, 2 or 3):\n1. Caesar\n2. Greek\n3. Cobb"); - // ... handle salad subtype choice - break; - default: - alert("Error: Invalid food choice."); -} +// 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."); +} \ No newline at end of file From 61aa85acfc8087f3e3db6066e761f3f6635a1a1c Mon Sep 17 00:00:00 2001 From: Nella Edvardsson Date: Sun, 8 Sep 2024 15:34:04 +0200 Subject: [PATCH 6/7] read me --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 33c7e601..46c15d30 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# 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 From 2499d1b137a9111e612a4f6e9443d53ab909c3f4 Mon Sep 17 00:00:00 2001 From: Nella Edvardsson Date: Sun, 8 Sep 2024 15:38:13 +0200 Subject: [PATCH 7/7] netlify link --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 46c15d30..d33fdca3 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,4 @@ I did not have much time this week and I also found it very challenging to get s ## View it live +https://pizzaplz.netlify.app/ \ No newline at end of file