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

Mikas pizza bot #156

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
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
# 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.

## 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?

## 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
A javascript chatbot for pizza orders using switch statements. Deployed at mikaspizzeria.netlify.com
2 changes: 1 addition & 1 deletion code/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
118 changes: 108 additions & 10 deletions code/script.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,117 @@
// Start here

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

const person = prompt("Please enter your name", "Harry Potter");

person && alert(`Hi ${person}`);

// Step 2 - Food choice
// Your code goes here

const food = prompt(
"What type of food do you want? Enter a number: 1 - Pizza 2 - Pasta 3 - Salad",
""
);

const foodNumber = Number(food);

if (foodNumber >= 1 && foodNumber <= 3) {
alert(`Great choice!`);
} else {
alert(`Invalid input, please choose a number between 1-3`);
}

// Step 3 - Subtype choice
// Your code goes here

let selectedFoodType = "";

switch (food) {
case "1":
{
const pizza = prompt(
`What type of pizza do you want? 1 - Margerita 2 - Capricciosa 3 - Hawaii`,
""
);
if (pizza === "1") {
selectedFoodType = "Margerita";
alert(`${selectedFoodType} is a great choice!`);
} else if (pizza === "2") {
selectedFoodType = "Capricciosa";
alert(`${selectedFoodType} is a great choice!`);
} else if (pizza === "3") {
selectedFoodType = "Hawaii";
alert(`${selectedFoodType} is a great choice!`);
} else {
alert(`Invalid input, please choose a number between 1-3`);
}
}
break;
case "2":
{
const pasta = prompt(
`What type of pasta do you want? 1 - Pomodoro 2 - Carbonara 3 - Arrabiata`,
""
);
if (pasta === "1") {
selectedFoodType = "Pomodoro";
alert(`${selectedFoodType} is a great choice!`);
} else if (pasta === "2") {
selectedFoodType = "Carbonara";
alert(`${selectedFoodType} is a great choice!`);
} else if (pasta === "3") {
selectedFoodType = "Arrabiata";
alert(`${selectedFoodType} is a great choice!`);
} else {
alert(`Invalid input, please choose a number between 1-3`);
}
}
break;
case "3": {
const salad = prompt(
`What type of salad do you want? 1 - Cucumber 2 - Tomato 3 - Carrot`,
""
);
if (salad === "1") {
selectedFoodType = "Cucumber salad";
alert(`${selectedFoodType} is a great choice!`);
} else if (salad === "2") {
selectedFoodType = "Tomoato salad";
alert(`${selectedFoodType} is a great choice!`);
} else if (salad === "3") {
selectedFoodType = "Carrot salad";
alert(`${selectedFoodType} is a great choice!`);
} else {
alert(`Invalid input, please choose a number between 1-3`);
}
break;
}
default:
alert("Invalid food selection");
}

// Step 4 - Age
// Your code goes here
const age = prompt(`Is this food for a child or an adult? Type your age:`, "");

const ageString = () => {
const ageNumber = Number(age);
if (ageNumber <= 18) {
return "child";
} else if (ageNumber >= 18) {
return "adult";
} else {
return alert(`Invalid Input, age is just a number!`);
}
};

const ageResult = ageString();

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

const confirmation =
prompt(`One ${ageResult} ${selectedFoodType} ordered! That'll be 150SEK. Do you want to proceed with the order?
1 - Yes
2 - No `);

if (confirmation === "1") {
alert(`Thanks for your order!`);
} else {
alert(`See you next time!`);
}