-
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
The French Bot - Chatbot project - Jenny A #295
Open
jempa182
wants to merge
2
commits into
Technigo:main
Choose a base branch
from
jempa182: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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
# Project Name | ||
|
||
Replace this readme with your own information about your project. | ||
The French Chatbot | ||
|
||
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? | ||
The project was to build a functional chatbot interface using JavaScript, HTML, and CSS. Creating a chatbot that can interact with users, ask questions, display messages, and respond with precision. | ||
|
||
## 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. | ||
https://thefrenchbot.netlify.app/ |
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.
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.
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 rel="preconnect" href="https://fonts.googleapis.com"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link href="https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet"> | ||
|
||
<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> | ||
<title>The French Chatbot</title> | ||
</head> | ||
|
||
<script src="./script.js"></script> | ||
</body> | ||
<body> | ||
<h1>The French Bot</h1> | ||
<main> | ||
<section class="chat" id="chat"></section> | ||
<div class="input-wrapper" id="input-wrapper"> | ||
<form id="name-form"> | ||
<input id="name-input" type="text" placeholder="Type your message..." /> | ||
<button class="send-btn" type="submit"> | ||
Send | ||
</button> | ||
</form> | ||
<div id="button-container" style="display: none;"></div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep styling out of the HTML file 👀 |
||
</div> | ||
</main> | ||
|
||
</html> | ||
<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,133 @@ | ||
// DOM selectors (variables that point to selected DOM elements) goes here 👇 | ||
const chat = document.getElementById('chat') | ||
// DOM selectors | ||
const chat = document.getElementById('chat'); | ||
const nameInput = document.getElementById('name-input'); | ||
const form = document.getElementById('name-form'); | ||
const buttonContainer = document.getElementById('button-container'); | ||
|
||
// Functions goes here 👇 | ||
// Conversation state | ||
let userName = ''; | ||
|
||
// 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') { | ||
chat.innerHTML += ` | ||
<section class="user-msg"> | ||
<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') { | ||
chat.innerHTML += ` | ||
<section class="bot-msg"> | ||
<img src="assets/bot.png" alt="Bot" /> | ||
<div class="bubble bot-bubble"> | ||
<p>${message}</p> | ||
</div> | ||
</section> | ||
` | ||
// Sound effects | ||
const sendSound = new Audio('assets/message-sent.mp3'); | ||
const receiveSound = new Audio('assets/new-notification.mp3'); | ||
|
||
// Functions | ||
|
||
// Play send sound | ||
const playSendSound = () => { | ||
sendSound.play(); | ||
}; | ||
|
||
// Play receive sound | ||
const playReceiveSound = () => { | ||
receiveSound.play(); | ||
}; | ||
|
||
// Final message | ||
const goodbyeMessage = () => { | ||
showMessage(`Félicitations, ${userName}! You've completed the French learning session. Au revoir!`, 'bot'); | ||
}; | ||
|
||
// Handle user's answer to French questions | ||
const handleFrenchAnswer = (answer, correctAnswer, nextQuestion) => { | ||
showMessage(answer, 'user'); | ||
playSendSound(); | ||
buttonContainer.style.display = 'none'; // Hide buttons | ||
setTimeout(() => { | ||
if (answer === correctAnswer) { | ||
showMessage(`Excellent! "${answer}" is correct. 🥐`, 'bot'); | ||
} else { | ||
showMessage(`Not quite.. The correct answer is "${correctAnswer}".`, 'bot'); | ||
} | ||
playReceiveSound(); | ||
setTimeout(() => nextQuestion(), 1000); | ||
}, 1000); | ||
}; | ||
|
||
// Create buttons for French questions | ||
const createFrenchButtons = (options, correctAnswer, nextQuestion) => { | ||
form.style.display = 'none'; // Hide form | ||
buttonContainer.innerHTML = options.map(option => | ||
`<button type="button" class="button-class">${option}</button>` | ||
).join(''); | ||
buttonContainer.style.display = 'flex'; // Show buttons | ||
|
||
// Add event listeners to buttons | ||
buttonContainer.querySelectorAll('button').forEach(button => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice usage of forEach 👍 |
||
button.addEventListener('click', () => handleFrenchAnswer(button.textContent, correctAnswer, nextQuestion)); | ||
}); | ||
}; | ||
|
||
// Ask how to say "Yes" in French | ||
const askYesInFrench = () => { | ||
showMessage("How do you say 'Yes' in French?", 'bot'); | ||
playReceiveSound(); | ||
createFrenchButtons(["Non", "Oui", "Peut-être"], "Oui", goodbyeMessage); | ||
}; | ||
|
||
// Ask how to say "Thank you" in French | ||
const askThankYouInFrench = () => { | ||
showMessage("How do you say 'Thank you' in French?", 'bot'); | ||
playReceiveSound(); | ||
createFrenchButtons(["S'il vous plaît", "Merci", "Oui"], "Merci", askYesInFrench); | ||
}; | ||
|
||
// Ask how to say "Hello" in French | ||
const askHelloInFrench = () => { | ||
showMessage("How do you say 'Hello' in French?", 'bot'); | ||
playReceiveSound(); | ||
createFrenchButtons(["Bonjour", "Merci", "Au revoir"], "Bonjour", askThankYouInFrench); | ||
}; | ||
|
||
// Start French lesson | ||
const startFrenchLesson = (name) => { | ||
userName = name; | ||
showMessage(`Enchanté, ${name}! 👩🏻🎨🍷 Let's learn some French.`, 'bot'); | ||
playReceiveSound(); | ||
setTimeout(askHelloInFrench, 1000); | ||
}; | ||
|
||
// Handle the name input | ||
const handleNameInput = (event) => { | ||
event.preventDefault(); | ||
const name = nameInput.value.trim(); | ||
if (name === '') { | ||
showMessage('', 'user'); | ||
playSendSound(); | ||
setTimeout(() => { | ||
showMessage(`You forgot to type your name`, 'bot'); | ||
playReceiveSound(); | ||
}, 1000); | ||
} else { | ||
showMessage(name, 'user'); | ||
playSendSound(); | ||
nameInput.value = ''; // Empty textfield | ||
setTimeout(() => startFrenchLesson(name), 1000); | ||
} | ||
}; | ||
|
||
// Event listener for the form | ||
form.addEventListener('submit', handleNameInput); | ||
|
||
// 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 | ||
} | ||
// Function that shows different chat bubbles depending on 'user' or 'bot' | ||
const showMessage = (message, sender) => { | ||
const messageHTML = ` | ||
<section class="${sender}-msg"> | ||
${sender === 'bot' ? '<img src="assets/bot.png" alt="Bot" />' : ''} | ||
<div class="bubble ${sender}-bubble"> | ||
<p>${message}</p> | ||
</div> | ||
${sender === 'user' ? '<img src="assets/user.png" alt="User" />' : ''} | ||
</section> | ||
`; | ||
chat.innerHTML += messageHTML; | ||
chat.scrollTop = chat.scrollHeight; | ||
}; | ||
|
||
// A function to start the conversation | ||
// Greeting message | ||
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 | ||
} | ||
|
||
// Eventlisteners goes here 👇 | ||
|
||
// 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) | ||
showMessage(`Bonjour! I'm the French Learning Bot. 🇫🇷🥖 What's your name?`, 'bot'); | ||
}; | ||
|
||
// Start by greeting the user | ||
setTimeout(greetUser, 1000); |
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
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.
haha 👌