Middle School Project

Welcome to the “Future Innovators: Cool STEM Projects to Change the World” series! In this project, you’re going to build an awesome AI Chatbot using Scratch—a beginner-friendly programming language designed for young coders. Your chatbot will be able to respond to questions, tell jokes, and even give advice.

By the end of this project, you will have created a fun and interactive chatbot that can be customized with different personalities, fun messages, and more. Best of all, you don’t need to know any complex coding—just drag, drop, and snap blocks together in Scratch!


What You Will Learn

  • How to use Scratch to create interactive programs.
  • How to design a chatbot that can respond to text inputs.
  • How to use basic Artificial Intelligence concepts, like giving responses based on user input.

STEM Learning Process

1. Science: Explore how computers understand language and respond to user input.
2. Technology: Learn how to use Scratch to program interactive apps.
3. Engineering: Design a chatbot that can communicate with users in a fun and engaging way.
4. Math: Understand simple logic and conditions to make your chatbot smarter.


What You Need

  • A computer with internet access.
  • A Scratch account (free). You can create one at scratch.mit.edu.

Getting Started with Scratch

Step 1: Sign Up for Scratch

If you don’t already have a Scratch account, go to scratch.mit.edu, click Join Scratch, and create a free account. This will let you save your projects and share them with others.

Step 2: Create a New Project

Once logged in, click Create in the top-left corner to start a new project.

Step 3: Choose Your Sprite (Character)

You can choose any sprite (character) for your chatbot. For this example, we’ll use the default Cat sprite, but feel free to choose one that you think represents your chatbot’s personality.


Building Your AI Chatbot

Now that your project is ready, let’s start creating your chatbot!

Step 1: Add a “When Green Flag Clicked” Block

This block will start your program whenever the green flag is clicked. You can find it in the Events section.

  1. Go to the Events section.
  2. Drag the block “When [green flag] clicked” onto the workspace.

Step 2: Add the “Ask” Block

This block will ask the user a question and wait for their input (text). The user’s answer will be stored in the built-in “answer” variable.

  1. Go to the Sensing section.
  2. Drag the block “ask [What’s your name?] and wait” onto the workspace and connect it to the green flag block.
  3. Customize the question! You can change it to something like:
  • “Hi! What’s your name?”

Step 3: Add a Response Based on the User’s Input

Now, let’s make your chatbot respond. To do this, we’ll use an “if-else” block to check the user’s answer.

  1. Go to the Control section.
  2. Drag an “if [ ] then” block onto the workspace.
  3. Go to the Operators section and drag the “equals [ ]” block into the if statement.
  4. In the Sensing section, drag the “answer” block into one side of the equals block.
  5. Type your custom response in the other side of the equals block, such as “Alice”.
  6. Inside the if block, add a “say [ ] for 2 seconds” block from the Looks section and make the chatbot say:
  • “Nice to meet you, Alice!”

Step 4: Add More Responses

You can customize your chatbot to recognize different names or inputs. Here’s how to handle multiple responses:

  1. After the first if-else block, add another “if-else” block to check if the user entered a different name (e.g., Bob).
  2. You can keep adding different answers and responses for various inputs. Here’s an example:
  • If name equals “Bob”, the chatbot could say:
    • “Hey Bob! How are you today?”

Step 5: Add an Else Statement for Unknown Inputs

What if the user types something unexpected? Let’s add an “else” part so the chatbot always has a response.

  1. At the bottom of your last “if-else” block, add an “else” statement.
  2. Inside the else block, add a response like:
  • “I don’t know that name, but it’s nice to meet you!”

Adding More Fun Features

Feature 1: Joke Telling

Let’s add a feature where your chatbot can tell jokes if the user asks for one.

  1. After the name-checking part of your chatbot, add another “ask” block that says:
  • “Do you want to hear a joke?”
  1. Add an “if-else” block to check if the user says “yes”.
  2. Inside the if block, add a “say [ ]” block that tells a joke:
  • “Why don’t skeletons fight each other? Because they don’t have the guts!”
  1. Inside the else block, make the chatbot say:
  • “Okay, no jokes for now!”

Feature 2: Giving Advice

You can also make your chatbot give advice based on user input!

  1. Add an “ask” block that says:
  • “Do you need advice?”
  1. Add an “if-else” block to check if the user says “yes”.
  2. Inside the if block, have the chatbot say:
  • “Stay curious and keep learning new things!”

Testing Your Chatbot

Once you’ve finished coding, it’s time to test your chatbot!

  1. Click the Green Flag: Your chatbot will ask for your name.
  2. Respond to Your Chatbot: Type in your name and see how the chatbot responds. If you added the joke-telling feature, try typing “yes” when the chatbot asks if you want to hear a joke.
  3. Customize Further: Add more responses, jokes, or even a personality to make your chatbot unique.

Customize and Expand Your Chatbot

This chatbot is fully customizable, and you can add any features you want! Here are some ideas for making your chatbot even cooler:

Add Emotions to Your Chatbot

  • Use the Looks blocks to change your chatbot’s expression based on the conversation. For example, when the chatbot tells a joke, you can make it smile.

Create a Mini Quiz Game

  • Add more questions and have your chatbot quiz the user. You can use the “if-else” blocks to give different responses based on the user’s answers.

Add Random Fun Facts

  • Make your chatbot give random fun facts by using the “pick random [ ] to [ ]” block and a list of fun facts.

What’s Next?

Great job! You’ve created your own AI Chatbot using Scratch. It can ask questions, respond to your answers, tell jokes, and give advice. But don’t stop here—you can keep adding more features and making your chatbot even more interactive.

In our next project, we’ll be building a Virtual Pet using Scratch. Your pet will be able to respond to different actions like feeding, playing, and more. Stay tuned for more cool and fun STEM projects, released weekly!


Resources and Additional Help


That wraps up the middle school AI chatbot project—keep exploring and have fun with coding!

Categorized in: