A chatbot is a computer program that reads what a person types and sends back a helpful or friendly answer. In Scratch, you can build a simple chatbot with colorful blocks, sprites, speech bubbles, and a few rules. This project matters because it teaches the basic idea behind many AI tools: a program can take input, check it, and choose a response.
It is also a fun school project because you can design the bot's personality, look, and conversation style.
Understanding Build a Chatbot in Scratch
A Scratch chatbot does not understand language in the way a person does. It follows instructions in a fixed order. This is important when you design its rules.
If a student types Hello with a capital letter, a rule that checks for hello may not match. Extra spaces can cause the same problem. A beginner chatbot works best when it gives users clear choices, such as typing one of three listed words.
You can make the conversation feel smoother by showing examples on the screen. Another useful approach is to check for several likely versions of the same reply, including hi, hello, and hey.
The order of your rules changes the result. Scratch checks scripts from top to bottom, so a broad rule can block a more specific rule if it comes first. Put detailed replies before general fallback replies.
For example, a bot that recognizes a favorite subject should reply to that before using a default message for unknown input. A fallback response is valuable because users rarely type exactly what the designer expects.
It can politely say that it did not recognize the reply, then show the available choices again. This keeps the program from seeming stuck.
Variables help a chatbot remember parts of a conversation. A name variable can be used later in a greeting, making the response feel connected to earlier input. You can store a score, a chosen topic, or the number of turns in the conversation.
These stored values create simple conversation state. A quiz bot might remember how many answers were correct. A school helper bot might remember whether the user selected math, science, or reading.
Reset important variables when the green flag is clicked. Without a reset, an old value may remain from the previous run and confuse your testing.
Testing is where most of the learning happens. Try expected replies, misspellings, blank replies, capital letters, and random words. Watch the variable display while the project runs.
This shows whether the program saved the input you expected. If a response fails, check spelling, spaces, and the location of each condition. Real customer service menus, game characters, and website help tools often use similar decision rules, even when their systems are much larger.
Keep personal information out of a school chatbot. A project can be friendly and useful without asking for real names, addresses, passwords, or private details.
Key Facts
- A simple chatbot follows the pattern input -> check -> response.
- The Scratch ask block asks a question and saves the user's typed reply in answer.
- A variable can store information, such as userName = answer.
- An if then block runs code only when its condition is true.
- A basic response rule can be written as if answer = "hello" then say "Hi there!".
- Use repeat or forever to keep the chatbot conversation going.
Vocabulary
- Chatbot
- A chatbot is a program that answers a user's typed or spoken messages.
- Sprite
- A sprite is a character or object in Scratch that can be programmed with code blocks.
- Input
- Input is information a user gives to a program, such as typing an answer.
- Variable
- A variable is a named place to store information that a program can use later.
- Condition
- A condition is a true-or-false test used to decide which code should run.
Common Mistakes to Avoid
- Forgetting to use the answer value after an ask block. The chatbot cannot respond to what the user typed unless the code checks answer or stores it in a variable.
- Putting all replies in one long say block. This is wrong because the bot will always say the same thing instead of choosing a response based on the user's message.
- Checking for only one exact spelling, such as "Hi" but not "hi". Scratch text comparisons must match, so the bot may miss a correct greeting if capitalization or spelling is different.
- Not adding a repeat or forever loop for the conversation. Without a loop, the chatbot may ask one question and stop instead of continuing the chat.
Practice Questions
- 1 A Scratch bot asks, "What is your name?" and the user types Maya. Write the variable assignment that stores the reply in a variable called userName.
- 2 A chatbot has 3 possible responses: one for "hello", one for "help", and one for "bye". How many if then checks are needed if each response has its own condition?
- 3 Your chatbot keeps saying, "I do not understand" even when the user types hello. Explain two possible reasons this could happen and how you would fix them.