-
Notifications
You must be signed in to change notification settings - Fork 411
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
Seafood Restaurant #284
Open
gittebe
wants to merge
9
commits into
Technigo:main
Choose a base branch
from
gittebe:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Seafood Restaurant #284
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
81e1950
- added variables, function and event listener to store and display t…
gittebe 6f848d7
- changed the design
gittebe c4c8c5c
- changed the layout/design
gittebe a30fd33
- added asking for users name and stored the name in variable;
gittebe 371fb22
- added event listener for types of food buttons
gittebe b1ae1f4
- added choices for dishes
gittebe 7fa6ffb
- added @media
gittebe 1daba7f
- added link to live view in README
gittebe 9cd8b7f
- deleted not used HTML code
gittebe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<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" /> | ||
<title>Chatbot</title> | ||
</head> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<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" /> | ||
<title>Seafood Restaurant</title> | ||
</head> | ||
|
||
<body> | ||
<h1>Welcome to my chatbot!</h1> | ||
<main> | ||
<section class="chat" id="chat"></section> | ||
<div class="input-wrapper" id="input-wrapper"> | ||
<form id="name-form"> | ||
<label for="name-input">Name</label> | ||
<input id="name-input" type="text" /> | ||
<button class="send-btn" type="submit"> | ||
Send | ||
</button> | ||
</form> | ||
</div> | ||
</main> | ||
<body id='body'> | ||
<header id="header"> | ||
<h1>Seafood Restaurant</h1> | ||
</header> | ||
|
||
<script src="./script.js"></script> | ||
</body> | ||
<main id="main"> | ||
<section class="chat" id="chat"></section> | ||
|
||
</html> | ||
<form id="form" class="form"> | ||
|
||
</form> | ||
<!-- <div class="container-crab" id="content-main"> | ||
<img src="./assets/crab.png"></img> | ||
</div> --> | ||
</main> | ||
|
||
<script src="./script.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,247 @@ | ||
// DOM selectors (variables that point to selected DOM elements) goes here 👇 | ||
const chat = document.getElementById('chat') | ||
|
||
// Functions goes here 👇 | ||
const chat = document.getElementById("chat") | ||
const main = document.getElementById("main") | ||
|
||
|
||
|
||
// A function that will add a chat bubble in the correct place based on who the sender is | ||
const showMessage = (message, sender) => { | ||
// The if statement checks if the sender is the user and if that's the case it inserts | ||
// an HTML section inside the chat with the posted message from the user | ||
if (sender === 'user') { | ||
if (sender === "user") { | ||
chat.innerHTML += ` | ||
<section class="user-msg"> | ||
<div class="bubble user-bubble"> | ||
<section class="user-message"> | ||
<div class="bubble user-bubble"> | ||
<p>${message}</p> | ||
</div> | ||
<img src="assets/user.png" alt="User" /> | ||
</section> | ||
` | ||
// The else if statement checks if the sender is the bot and if that's the case it inserts | ||
// an HTML section inside the chat with the posted message from the bot | ||
} else if (sender === 'bot') { | ||
</div> | ||
<img src="./assets/user-chat.png" alt="user image" class="user-message-img"/> | ||
</section> | ||
` | ||
} else if (sender === "bot") { | ||
chat.innerHTML += ` | ||
<section class="bot-msg"> | ||
<img src="assets/bot.png" alt="Bot" /> | ||
<div class="bubble bot-bubble"> | ||
<p>${message}</p> | ||
</div> | ||
</section> | ||
` | ||
<section class="bot-message"> | ||
<img src="./assets/bot-chat.png" alt="user image" class="bot-message-img"/> | ||
<div class="bubble bot-bubble"> | ||
<p>${message}</p> | ||
</div> | ||
</section> | ||
` | ||
} | ||
|
||
// This little thing makes the chat scroll to the last message when there are too many to | ||
// be shown in the chat box | ||
chat.scrollTop = chat.scrollHeight | ||
} | ||
|
||
// A function to start the conversation | ||
const greetUser = () => { | ||
// Here we call the function showMessage, that we declared earlier with the argument: | ||
// "Hello there, what's your name?" for message, and the argument "bot" for sender | ||
showMessage("Hello there, what's your name?", 'bot') | ||
// Just to check it out, change 'bot' to 'user' here 👆 and see what happens | ||
// 5. Confirm order with yes/no | ||
// Confirm order shrimp | ||
|
||
const confirmOrder = (username) => { | ||
form.innerHTML += ` | ||
<div class="confirm-container" id="confirm-container"> | ||
<button class="confirm-button" id="yes-button" type="button">Yes</button> | ||
<button class="confirm-button" id="no-button" type="button">No</button> | ||
</div> | ||
` | ||
|
||
document | ||
.getElementById("yes-button") | ||
.addEventListener("click", () => { | ||
showMessage("yes", "user") | ||
showMessage(`Thank you, for your order, ${username}!`, "bot") | ||
form.innerHTML = "" | ||
}) | ||
document | ||
.getElementById("no-button") | ||
.addEventListener("click", () => { | ||
showMessage("no", "user") | ||
showMessage("Maybe another time", "bot") | ||
form.innerHTML = "" | ||
}) | ||
} | ||
|
||
|
||
// 4. Select dish and display message | ||
|
||
// Select fish dish | ||
|
||
const chooseFish = (username) => { | ||
form.innerHTML += ` | ||
<div class="dish-container" id="dish-container"> | ||
<button class="dish-button" id="salmon-button" type="button">Grilled Salmon</button> | ||
<button class="dish-button" id="fish-chips-button" type="button">Fish and Chips</button> | ||
</div> | ||
` | ||
document | ||
.getElementById("salmon-button") | ||
.addEventListener("click", () => { | ||
showMessage("salmon", "user") | ||
showMessage(`The Salmon for you. That will be $15. Are you sure you want to order this?`, "bot") | ||
form.innerHTML = "" | ||
confirmOrder(username) | ||
} | ||
) | ||
|
||
document | ||
.getElementById("fish-chips-button") | ||
.addEventListener("click", () => { | ||
showMessage("fish and chips", "user") | ||
showMessage(`${username}, you like to order Fish and Chips. Great! That will be $15. Are you sure you want to order this?`, "bot") | ||
form.innerHTML = "" | ||
confirmOrder(username) | ||
}) | ||
} | ||
|
||
|
||
// select shellfish dish | ||
|
||
const chooseShellfish = (username) => { | ||
|
||
form.innerHTML += ` | ||
<div class="dish-container" id="dish-container"> | ||
<button class="dish-button" id="shrimp-button" type="button">Shrimp</button> | ||
<button class="dish-button" id="lobster-button" type="button">Lobster</button> | ||
</div> | ||
` | ||
|
||
document | ||
.getElementById("shrimp-button") | ||
.addEventListener("click", () => { | ||
showMessage("shrimp", "user") | ||
showMessage(`${username}You like to order Shrimp. Great choice! That will be $15. Are you sure you want to order this?`, "bot") | ||
form.innerHTML = "" | ||
confirmOrder(username) | ||
} | ||
) | ||
|
||
document | ||
.getElementById("lobster-button") | ||
.addEventListener("click", () => { | ||
showMessage("lobster", "user") | ||
showMessage(`Great choice, ${username}! That will be $15. Are you sure you want to order this?`, "bot") | ||
form.innerHTML = "" | ||
confirmOrder(username) | ||
}) | ||
} | ||
|
||
const chooseMollusks = (username) => { | ||
|
||
form.innerHTML += ` | ||
<div class="dish-container" id="dish-container"> | ||
<button class="dish-button" id="paella-button" type="button">Paella</button> | ||
<button class="dish-button" id="calamari-button" type="button">Calamari</button> | ||
</div> | ||
` | ||
|
||
document | ||
.getElementById("paella-button") | ||
.addEventListener("click", () => { | ||
showMessage("paella", "user") | ||
showMessage(`Great choice, ${username}! That will be $15. Are you sure you want to order this?`, "bot") | ||
form.innerHTML = "" | ||
confirmOrder(username) | ||
} | ||
) | ||
|
||
document | ||
.getElementById("calamari-button") | ||
.addEventListener("click", () => { | ||
showMessage("calamari", "user") | ||
showMessage(`Great choice, ${username}! That will be $15. Are you sure you want to order this?`, "bot") | ||
form.innerHTML = "" | ||
confirmOrder(username) | ||
}) | ||
} | ||
|
||
|
||
//3. Select Foodtype | ||
|
||
const selectFoodtype = (username) => { | ||
showMessage(`Nice to meet you, ${username}! What type of food would you like to eat?`, "bot") | ||
|
||
// Buttons to select the food type | ||
form.innerHTML += ` | ||
<div class="foodtype-container" id="foodtype-container"> | ||
<button class="foodtype-button" id="fish-button" type="button">🐟 Fish</button> | ||
<button class="foodtype-button" id="shellfish-button" type="button">🦀 Shellfish</button> | ||
<button class="foodtype-button" id="mollusks-button" type="button">🦪 Mollusks</button> | ||
</div> | ||
` | ||
// Buttons to select the dishes & message | ||
|
||
document | ||
.getElementById("fish-button") | ||
.addEventListener("click", () => { | ||
showMessage("fish", "user") | ||
showMessage("Great choice! Select something from the menu!", "bot") | ||
form.innerHTML = "" | ||
chooseFish(username) | ||
}) | ||
|
||
document | ||
.getElementById("shellfish-button") | ||
.addEventListener("click", () => { | ||
showMessage("shellfish", "user") | ||
showMessage("Great choice! Select something from the menu!", "bot") | ||
form.innerHTML = "" | ||
chooseShellfish(username) | ||
}) | ||
|
||
document | ||
.getElementById("mollusks-button") | ||
.addEventListener("click", () => { | ||
showMessage("mollusks", "user") | ||
showMessage(`${username}, you like to order mullusks. Please choose a dish!`, "bot") | ||
form.innerHTML = "" | ||
chooseMollusks(username) | ||
}) | ||
} | ||
|
||
// Eventlisteners goes here 👇 | ||
//2. Asking for the users name, storing the name and display in chat | ||
|
||
const askName = () => { | ||
showMessage("Wonderful! What is your name?", "bot") | ||
|
||
form.innerHTML += ` | ||
<input class="input" id="name-input"></input> | ||
<button class="input-button" id="send-button" type="submit">ok</button> | ||
` | ||
|
||
const inputButton = document.getElementById("send-button") | ||
const input = document.getElementById('name-input') | ||
|
||
|
||
// Here we invoke the first function to get the chatbot to ask the first question when | ||
// the website is loaded. Normally we invoke functions like this: greeting() | ||
// To add a little delay to it, we can wrap it in a setTimeout (a built in JavaScript function): | ||
// and pass along two arguments: | ||
// 1.) the function we want to delay, and 2.) the delay in milliseconds | ||
// This means the greeting function will be called one second after the website is loaded. | ||
setTimeout(greetUser, 1000) | ||
inputButton.addEventListener("click", (event) => { | ||
event.preventDefault() | ||
|
||
const username = input.value | ||
|
||
if (username) { | ||
showMessage(username, "user") | ||
input.style.display = "none" | ||
form.innerHTML = "" | ||
selectFoodtype(username) | ||
} | ||
else { | ||
showMessage("Please enter your name.", "bot") | ||
} | ||
} | ||
) | ||
} | ||
|
||
|
||
// 1. Greeting and displaying the button | ||
|
||
const greetUser = () => { | ||
showMessage("Hello! Are you ready to start the order?", "bot") | ||
|
||
form.innerHTML += ` | ||
|
||
<button id="button" class="confirm-button" type="button">yes!</button> | ||
` | ||
|
||
const sendButton = document.getElementById("button") | ||
//Event: when user clicks the button, 'ok' will be displayed in the chat and the button will be taken off the screene | ||
|
||
sendButton.addEventListener("click", () => { | ||
showMessage("Yes!", "user") | ||
form.innerHTML = "" | ||
askName() | ||
}) | ||
|
||
} | ||
greetUser() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTML attributes should always be in double quotes