From b9062d7b393e255ea05cc712d50b0098881b635c Mon Sep 17 00:00:00 2001 From: Jonash189 Date: Thu, 5 Sep 2024 18:25:46 +0200 Subject: [PATCH 1/6] Added propmt and alert for userName + Added a prompt for the food options. --- code/index.html | 34 ++++++++++++++++++---------------- code/script.js | 33 +++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/code/index.html b/code/index.html index f7844d6b..2030bff0 100644 --- a/code/index.html +++ b/code/index.html @@ -1,18 +1,20 @@ - - - - Javascript Pizzeria - - - - -

Javascript Pizzeria

-

Logic is executed automatically

- - - + + + + + Javascript Pizzeria + + + + + +

Javascript Pizzeria

+

Logic is executed automatically

+ + + + \ No newline at end of file diff --git a/code/script.js b/code/script.js index 34ca0f34..e99dd87d 100644 --- a/code/script.js +++ b/code/script.js @@ -1,19 +1,44 @@ // Start here // Step 1 - Welcome and introduction -// Your code goes here alert( `Welcome to our Javascript Pizzeria. Ready to Start? - Click 'OK' to begin.` ) +let userName = prompt("Hi there, whats your name?"); +alert(`Hi ${userName}! Order your food in the next step`) + + // Step 2 - Food choice -// Your code goes here + +let foodChoice = prompt(" What kind of food do you want? 1. Pizza 2. Pasta 3. Sallad ") + + +let selectedFood +let subChoice + +if (foodChoice === "1") { + selectedFood = "Pizza"; +} +else if (foodChoice === "2") { + selectedFood = "Pasta"; +} +else if (foodChoice === "3") { + selectedFood = "Sallad"; +} else { + selectedFood = "unknown"; + alert("Error"); +} // Step 3 - Subtype choice -// Your code goes here + + // Step 4 - Age // Your code goes here // Step 5 - Order confirmation -// Your code goes here + + + + From 1bfb54ae4cdaf60502a9bfa90312472742d0fd78 Mon Sep 17 00:00:00 2001 From: Jonash189 Date: Thu, 5 Sep 2024 18:45:45 +0200 Subject: [PATCH 2/6] Adding subchoice --- code/script.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/code/script.js b/code/script.js index e99dd87d..abb98fa8 100644 --- a/code/script.js +++ b/code/script.js @@ -14,8 +14,7 @@ alert(`Hi ${userName}! Order your food in the next step`) let foodChoice = prompt(" What kind of food do you want? 1. Pizza 2. Pasta 3. Sallad ") -let selectedFood -let subChoice + if (foodChoice === "1") { selectedFood = "Pizza"; @@ -30,9 +29,57 @@ else if (foodChoice === "3") { alert("Error"); } + // Step 3 - Subtype choice +if (foodChoice === "1") { + selectedFood = "Pizza"; + let subChoice = prompt("What kind of pizza do you want? 1. Hawaii 2. Margarita 3. Calzone"); + + if (subChoice === "1") { + subChoice = "Hawaii"; + } else if (subChoice === "2") { + subChoice = "Margarita"; + } else if (subChoice === "3") { + subChoice = "Calzone"; + } else { + subChoice = "Unknown pizza"; + alert("Invalid choice"); + } + +} else if (foodChoice === "2") { + selectedFood = "Pasta"; + + let subChoice = prompt("What kind of pasta do you want? 1. Bolognese 2. Carbonara 3. Meatballs"); + + if (subChoice === "1") { + subChoice = "Bolognese"; + } else if (subChoice === "2") { + subChoice = "Carbonara"; + } else if (subChoice === "3") { + subChoice = "Meatballs"; + } else { + subChoice = "Unknown pasta"; + alert("Invalid choice"); + } + +} else if (foodChoice === "3") { + selectedFood = "Sallad"; + + let subChoice = prompt("What kind of sallad do you want? 1. Caesar 2. Chicken 3. Cheese & Ham"); + + if (subChoice === "1") { + subChoice = "Caesar"; + } else if (subChoice === "2") { + subChoice = "Chicken"; + } else if (subChoice === "3") { + subChoice = "Cheese & Ham"; + } else { + subChoice = "Unknown sallad"; + alert("Invalid choice"); + } +} // Step 4 - Age // Your code goes here From 84c889b8e3d548e6215f2dffbf8bb841714fe1ef Mon Sep 17 00:00:00 2001 From: Jonash189 Date: Thu, 5 Sep 2024 19:56:03 +0200 Subject: [PATCH 3/6] Added age and order confirmation alert --- code/script.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/code/script.js b/code/script.js index abb98fa8..701d797f 100644 --- a/code/script.js +++ b/code/script.js @@ -8,6 +8,9 @@ alert( let userName = prompt("Hi there, whats your name?"); alert(`Hi ${userName}! Order your food in the next step`) +let selectedFood; +let subChoice = ""; // Vi skapar subChoice här så alla kan se den! + // Step 2 - Food choice @@ -15,7 +18,6 @@ let foodChoice = prompt(" What kind of food do you want? 1. Pizza 2. Pasta 3. S - if (foodChoice === "1") { selectedFood = "Pizza"; } @@ -35,7 +37,7 @@ else if (foodChoice === "3") { if (foodChoice === "1") { selectedFood = "Pizza"; - let subChoice = prompt("What kind of pizza do you want? 1. Hawaii 2. Margarita 3. Calzone"); + subChoice = prompt("What kind of pizza do you want? 1. Hawaii 2. Margarita 3. Calzone"); if (subChoice === "1") { subChoice = "Hawaii"; @@ -51,7 +53,7 @@ if (foodChoice === "1") { } else if (foodChoice === "2") { selectedFood = "Pasta"; - let subChoice = prompt("What kind of pasta do you want? 1. Bolognese 2. Carbonara 3. Meatballs"); + subChoice = prompt("What kind of pasta do you want? 1. Bolognese 2. Carbonara 3. Meatballs"); if (subChoice === "1") { subChoice = "Bolognese"; @@ -67,7 +69,7 @@ if (foodChoice === "1") { } else if (foodChoice === "3") { selectedFood = "Sallad"; - let subChoice = prompt("What kind of sallad do you want? 1. Caesar 2. Chicken 3. Cheese & Ham"); + subChoice = prompt("What kind of sallad do you want? 1. Caesar 2. Chicken 3. Cheese & Ham"); if (subChoice === "1") { subChoice = "Caesar"; @@ -82,10 +84,20 @@ if (foodChoice === "1") { } // Step 4 - Age -// Your code goes here + +let age = prompt(" Is this order for an 1. Adult or 2. Child?") + +if (age === "1") { + age = "Adult"; +} else if (age === "2") { + age = "Child"; +} + // Step 5 - Order confirmation +alert(`Thank you, ${userName}! You have ordered a ${subChoice} for an ${age}.`); + From 35f6ae291f7a517fa3e434700ca9e4334dfcbaf8 Mon Sep 17 00:00:00 2001 From: Jonash189 Date: Sun, 8 Sep 2024 18:18:48 +0200 Subject: [PATCH 4/6] Adding comments to the code --- code/script.js | 51 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/code/script.js b/code/script.js index 701d797f..6d2a2724 100644 --- a/code/script.js +++ b/code/script.js @@ -1,22 +1,22 @@ -// Start here +// Step 1 - The program starts by showing an alert() to welcome the user, and the ordering process begins after they click "OK." -// Step 1 - Welcome and introduction alert( - `Welcome to our Javascript Pizzeria. Ready to Start? - Click 'OK' to begin.` + `Welcome to Jonas' pizza restaurant. When you are ready to order - Click 'OK' to start.` ) -let userName = prompt("Hi there, whats your name?"); -alert(`Hi ${userName}! Order your food in the next step`) - -let selectedFood; -let subChoice = ""; // Vi skapar subChoice här så alla kan se den! +// Step 2 - A prompt() asks for the user’s name, and the input is stored in the userName variable, followed by an alert() displaying a personalized greeting. +let userName = prompt("Hi there, what's your name?"); +alert(`Hi ${userName}! You'll order your food in the next step.`) -// Step 2 - Food choice +// This makes the variables accessible throughout the entire program. +let selectedFood; +let subChoice = ""; -let foodChoice = prompt(" What kind of food do you want? 1. Pizza 2. Pasta 3. Sallad ") +// Step 3 - The user selects a main dish (Pizza, Pasta, or Salad) using a prompt(), and the choice is saved in the foodChoice variable. The if-else structure sets the selectedFood variable based on this input. +let foodChoice = prompt("What kind of food do you want? 1. Pizza 2. Pasta 3. Salad") if (foodChoice === "1") { selectedFood = "Pizza"; @@ -25,14 +25,16 @@ else if (foodChoice === "2") { selectedFood = "Pasta"; } else if (foodChoice === "3") { - selectedFood = "Sallad"; + selectedFood = "Salad"; } else { selectedFood = "unknown"; alert("Error"); } +alert(`Thanks, you chose ${selectedFood}!`) -// Step 3 - Subtype choice + +// Step 4 - If the user selected a main dish, a prompt() asks for a specific type (e.g., Hawaii for pizza), storing the result in the subChoice variable. The if-else structure determines which subtype is selected or sets subChoice to "Unknown" for invalid inputs. if (foodChoice === "1") { selectedFood = "Pizza"; @@ -67,25 +69,25 @@ if (foodChoice === "1") { } } else if (foodChoice === "3") { - selectedFood = "Sallad"; + selectedFood = "Salad"; - subChoice = prompt("What kind of sallad do you want? 1. Caesar 2. Chicken 3. Cheese & Ham"); + subChoice = prompt("What kind of salad do you want? 1. Caesar salad 2. Chicken salad 3. Cheese & Ham salad"); if (subChoice === "1") { - subChoice = "Caesar"; + subChoice = "Caesar salad"; } else if (subChoice === "2") { - subChoice = "Chicken"; + subChoice = "Chicken salad"; } else if (subChoice === "3") { - subChoice = "Cheese & Ham"; + subChoice = "Cheese & Ham salad"; } else { - subChoice = "Unknown sallad"; + subChoice = "Unknown salad"; alert("Invalid choice"); } } -// Step 4 - Age +// Step 5 - The program asks the user with a prompt() whether the order is for an adult or child, storing the input in the age variable, and an if-else checks the response. -let age = prompt(" Is this order for an 1. Adult or 2. Child?") +let age = prompt("Is this order for an 1. Adult or 2. Child?") if (age === "1") { age = "Adult"; @@ -93,11 +95,6 @@ if (age === "1") { age = "Child"; } +// Step 6 - An alert() displays a confirmation message combining the userName, subChoice, and age variables to summarize the order. -// Step 5 - Order confirmation - -alert(`Thank you, ${userName}! You have ordered a ${subChoice} for an ${age}.`); - - - - +alert(`Thank you, ${userName}! You have ordered a ${subChoice} for an ${age}. This will be 300 SEK, you pay at the restaurant. See you soon!`); From 211af6fe616502a2a9ebcbbfbfc1278fbec812a9 Mon Sep 17 00:00:00 2001 From: Jonash189 Date: Sun, 8 Sep 2024 18:21:07 +0200 Subject: [PATCH 5/6] Cleaning the code --- code/script.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/code/script.js b/code/script.js index 6d2a2724..3d623b75 100644 --- a/code/script.js +++ b/code/script.js @@ -1,8 +1,6 @@ // Step 1 - The program starts by showing an alert() to welcome the user, and the ordering process begins after they click "OK." -alert( - `Welcome to Jonas' pizza restaurant. When you are ready to order - Click 'OK' to start.` -) +alert(`Welcome to Jonas pizza restaurant. When you are ready to order - Click 'OK' to start.`) // Step 2 - A prompt() asks for the user’s name, and the input is stored in the userName variable, followed by an alert() displaying a personalized greeting. From 4cae938d82e3c87d78c0fdc6c1677183e0a5e7b8 Mon Sep 17 00:00:00 2001 From: Jonash189 Date: Sun, 8 Sep 2024 18:46:34 +0200 Subject: [PATCH 6/6] making space between the diffrent foodchoices. (\n) --- code/script.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/script.js b/code/script.js index 3d623b75..f5f6bf3b 100644 --- a/code/script.js +++ b/code/script.js @@ -14,7 +14,7 @@ let subChoice = ""; // Step 3 - The user selects a main dish (Pizza, Pasta, or Salad) using a prompt(), and the choice is saved in the foodChoice variable. The if-else structure sets the selectedFood variable based on this input. -let foodChoice = prompt("What kind of food do you want? 1. Pizza 2. Pasta 3. Salad") +let foodChoice = prompt("What kind of food do you want? \n1. Pizza\n2. Pasta\n3. Salad") if (foodChoice === "1") { selectedFood = "Pizza"; @@ -37,7 +37,7 @@ alert(`Thanks, you chose ${selectedFood}!`) if (foodChoice === "1") { selectedFood = "Pizza"; - subChoice = prompt("What kind of pizza do you want? 1. Hawaii 2. Margarita 3. Calzone"); + subChoice = prompt("What kind of pizza do you want? \n1. Hawaii \n2. Margarita \n3. Calzone"); if (subChoice === "1") { subChoice = "Hawaii"; @@ -53,7 +53,7 @@ if (foodChoice === "1") { } else if (foodChoice === "2") { selectedFood = "Pasta"; - subChoice = prompt("What kind of pasta do you want? 1. Bolognese 2. Carbonara 3. Meatballs"); + subChoice = prompt("What kind of pasta do you want? \n1. Bolognese \n2. Carbonara \n3. Meatballs"); if (subChoice === "1") { subChoice = "Bolognese"; @@ -69,7 +69,7 @@ if (foodChoice === "1") { } else if (foodChoice === "3") { selectedFood = "Salad"; - subChoice = prompt("What kind of salad do you want? 1. Caesar salad 2. Chicken salad 3. Cheese & Ham salad"); + subChoice = prompt("What kind of salad do you want? \n1. Caesar salad \n2. Chicken salad \n3. Cheese & Ham salad"); if (subChoice === "1") { subChoice = "Caesar salad"; @@ -85,7 +85,7 @@ if (foodChoice === "1") { // Step 5 - The program asks the user with a prompt() whether the order is for an adult or child, storing the input in the age variable, and an if-else checks the response. -let age = prompt("Is this order for an 1. Adult or 2. Child?") +let age = prompt("Is this order for an \n1. Adult or \n2. Child?") if (age === "1") { age = "Adult"; @@ -95,4 +95,4 @@ if (age === "1") { // Step 6 - An alert() displays a confirmation message combining the userName, subChoice, and age variables to summarize the order. -alert(`Thank you, ${userName}! You have ordered a ${subChoice} for an ${age}. This will be 300 SEK, you pay at the restaurant. See you soon!`); +alert(`Thank you, ${userName}! You have ordered a ${subChoice} for an ${age}. \nThis will be 150 SEK, you pay at the restaurant. See you soon!`);