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

Jonas pizza project #152

Open
wants to merge 6 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
34 changes: 18 additions & 16 deletions code/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Javascript Pizzeria</title>
<link rel="stylesheet" href="./style.css" />
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet"
/>
</head>
<body>
<h1>Javascript Pizzeria</h1>
<p>Logic is executed automatically</p>
<script src="./script.js"></script>
</body>
</html>

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Javascript Pizzeria</title>
<link rel="stylesheet" href="./style.css" />
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet" />
</head>

<body>
<h1>Javascript Pizzeria</h1>
<p>Logic is executed automatically</p>
<script src="./script.js"></script>
</body>

</html>
107 changes: 93 additions & 14 deletions code/script.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,98 @@
// 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
// Your code goes here
alert(
`Welcome to our Javascript Pizzeria. Ready to Start? - Click 'OK' to begin.`
)
alert(`Welcome to Jonas pizza restaurant. When you are ready to order - Click 'OK' to start.`)

// Step 2 - Food choice
// Your code goes here
// 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.

// Step 3 - Subtype choice
// Your code goes here
let userName = prompt("Hi there, what's your name?");
alert(`Hi ${userName}! You'll order your food in the next step.`)

// Step 4 - Age
// Your code goes here
// This makes the variables accessible throughout the entire program.
let selectedFood;
let subChoice = "";
Comment on lines +11 to +12
Copy link
Contributor

Choose a reason for hiding this comment

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

As we talked about during demo, try to be consistent and declare all variables as the type you expect them to be (so empty string works fine for strings)


// Step 5 - Order confirmation
// Your code goes here

// 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? \n1. Pizza\n2. Pasta\n3. Salad")

if (foodChoice === "1") {
selectedFood = "Pizza";
}
else if (foodChoice === "2") {
selectedFood = "Pasta";
}
else if (foodChoice === "3") {
selectedFood = "Salad";
} else {
selectedFood = "unknown";
alert("Error");
}

alert(`Thanks, you chose ${selectedFood}!`)


// 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";

subChoice = prompt("What kind of pizza do you want? \n1. Hawaii \n2. Margarita \n3. 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";

subChoice = prompt("What kind of pasta do you want? \n1. Bolognese \n2. Carbonara \n3. 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 = "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";
} else if (subChoice === "2") {
subChoice = "Chicken salad";
} else if (subChoice === "3") {
subChoice = "Cheese & Ham salad";
} else {
subChoice = "Unknown salad";
alert("Invalid choice");
}
}

// 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 \n1. Adult or \n2. Child?")

if (age === "1") {
age = "Adult";
} else if (age === "2") {
age = "Child";
}

// 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}. \nThis will be 150 SEK, you pay at the restaurant. See you soon!`);