Skip to content

Chapter 2: Thinking Like a Computer

Step by step, exactly.

Welcome back, AI Explorers! In Chapter 1, we learned that AI is not a magic wand or a tiny person living inside your tablet. It is a computer program that finds patterns and makes really good guesses.

But if computers don’t have brains like we do, how do they know what to do?

The secret is that computers are not very smart on their own. They don’t have “common sense.” If you tell a human to “clean your room,” they know that means pick up toys, make the bed, and put dirty clothes in the hamper. If you tell a computer to “clean your room,” it will just sit there, completely confused.

Computers need us to tell them exactly what to do, step by step. In this chapter, we are going to learn how to think like a computer so we can give AI the best instructions possible.


Have you ever looked at a giant, messy pile of building bricks and felt totally overwhelmed? Building a massive spaceship seems impossible if you just stare at the mountain of plastic. Your brain might panic and say, “This is too hard!”

But what happens if you open the instruction booklet? It takes the giant, scary project and breaks it into tiny, easy steps. “First, find this blue square. Next, attach these two red pieces.” You do one tiny thing at a time, and before you know it, you have built a masterpiece.

Computer scientists do the exact same thing. They use a skill called computational thinkingcomputational thinking: A problem-solving approach used by computer scientists — breaking big, complicated problems into smaller, manageable steps that a computer can follow.. It has four parts, and you already use all of them:

Skill What It Means You Do It When…
Decomposition Break a big problem into small pieces You plan a party one job at a time
Pattern recognition Notice what repeats You see that every math problem on the page works the same way
Abstraction Ignore the details that don’t matter You draw a map with roads but not every tree
Algorithms Write the steps in order You follow a recipe

The first skill is the most important one for talking to AI. decompositiondecomposition: Breaking a big problem apart into its smallest, simplest pieces so it is easier to solve — one step at a time. (dee-com-po-ZI-shun) means breaking something apart into its smallest pieces.

Imagine trying to “throw a birthday party.” If you run around yelling “Party!”, nothing will happen. You have to decompose it:

  1. Pick a date.
  2. Make a guest list.
  3. Bake a cake.
  4. Buy balloons.

Computers need decomposition because they do not understand the “big picture.” They only understand the exact step in front of them.

If you want an AI to write a story, you can’t just say, “Write a good story.” That is too big and vague. The AI will guess, and you might end up with a boring story about a toaster. Instead, decompose the big idea into smaller questions:

Smaller Question Your Answer
Who is the main character? A clumsy dragon named Sparky
Where do they live? In a castle made of marshmallows
What is their problem? He sneezes fire and keeps roasting his house!
How do they solve it? He invents the world’s first dragon tissue

By answering these smaller questions one by one, you give the AI the exact puzzle pieces it needs. You are finally speaking the computer’s language!


Imagine that AI is a super-fast, world-class chef. This chef can chop vegetables at lightning speed and bake a cake in three seconds. But there is a catch: the chef has never seen food before and has no idea what a meal is.

If you are the recipe writer, you have to tell the chef exactly what to do. In the computer world, a recipe is called an algorithmalgorithm: A list of step-by-step instructions that tells a computer exactly what to do, in the right order — like a recipe for a meal. (AL-go-rith-um). An algorithm is a list of step-by-step instructions, in order.

When we give instructions to an AI, like typing a question into a chatbot, we call it a promptprompt: The instructions or question you type into an AI. A good prompt gives the AI all the details it needs to give you a great answer.. Getting good at writing prompts is called prompt engineeringprompt engineering: The skill of writing clear, specific prompts so that an AI gives you exactly the kind of answer you are looking for..

To be a good prompt engineer, you need to be specific:

❌ Vague Prompt ✅ Specific Prompt
“Tell me about space.” “Write a fun, three-paragraph story for a 4th grader about a dog who travels to Mars in a rocket ship.”

The vague prompt might get you a lesson about the space bar on a keyboard, or a college textbook answer. The specific prompt tells the AI exactly what recipe to follow.

A great prompt usually answers four questions. Think W-H-A-T:

  • Who is it for? “…for a 4th grader…”
  • How long? “…three paragraphs…”
  • About what, exactly? “…a dog who travels to Mars in a rocket ship…”
  • Tone or style? “…fun…”

You don’t need all four every time, but the more you include, the closer the answer will be to what you pictured.


Because computers don’t have human common sense, vague instructions can lead to very silly mistakes.

Let’s go back to our super-fast chef. Imagine you gave the chef this prompt: “Make me a bowl of cereal.”

Because you weren’t specific, the AI chef might grab a bowling ball, pour in a whole box of cereal (cardboard box and all!), and top it off with a gallon of orange juice instead of milk. You said “make a bowl of cereal,” and that’s technically what it did.

When a program or an instruction has a mistake in it, we call the mistake a bugbug: A mistake or error in an algorithm or computer program that causes it to behave in a way you didn't intend.. The word comes from a real moth that got stuck inside a giant computer in 1947! Finding and fixing bugs is called debuggingdebugging: The process of finding and fixing mistakes (bugs) in an algorithm or computer program..

Good debuggers do not panic, and they do not change everything at once. They:

  1. Look at what actually happened. (The chef used a bowling ball.)
  2. Find the step that caused it. (I never said what kind of bowl.)
  3. Change one thing. (Add “a cereal bowl from the cupboard.”)
  4. Try again.

When AI gives you a weird, silly, or unhelpful answer, it usually isn’t trying to be funny. It is usually because our prompt wasn’t clear enough. If an AI gets confused, don’t give up. Practice your computational thinking: break the problem down, rewrite your algorithm, and try a better prompt.


Real algorithms have two more tricks that make computers so powerful. You use them too.

A looploop: A part of an algorithm that repeats the same steps over and over until a job is done. means “do this again.” Instead of writing “take a step” a thousand times, a programmer writes “repeat ‘take a step’ until you reach the door.” AI uses loops constantly: it looks at one example, adjusts, looks at the next example, adjusts, millions of times. That is how it learns.

A decision means “if this, then that.” If it is raining, then take an umbrella. Otherwise, wear a hat. A spelling helper’s algorithm is full of decisions: if the word is not in the dictionary, then draw a red line.

When you put steps, loops, and decisions together, you can describe almost anything a computer does. Here is a whole algorithm for a robot picking up toys:

Repeat until the floor is empty: look for a toy. If it is a block, then put it in the block bin. Otherwise, put it in the toy box.

Read it slowly. A computer could follow that exactly. Could your little brother?


Chapter 2 Activity: The Peanut Butter and Jelly Robot 🥪

Section titled “Chapter 2 Activity: The Peanut Butter and Jelly Robot 🥪”

Your Mission: Practice writing the ultimate algorithm. You are going to program a “robot” (a friend, teacher, or family member) to make a peanut butter and jelly sandwich.

Write the step-by-step instructions for making a PB&J sandwich. Your robot has no common sense, so be specific. Don’t forget to tell them to open the bag of bread first! Add at least one decision: “If the lid is on the jar, then twist it off.”

Hand your instructions to your partner. Your partner must act like a robot and do exactly what is written, nothing more and nothing less. Did they smash the bread because you forgot to say “gently”? Did they put the peanut butter on the outside?

Every mistake is a bug. Laugh it off, fix one step at a time in your written instructions, and run the robot again. Count how many tries it took to get a real sandwich. That number is your debugging score!


  • I can name the four parts of computational thinking
  • I can decompose a big job into small steps in the right order
  • I know an algorithm is a list of steps, like a recipe
  • I know a prompt is the instructions I give an AI
  • I can write a specific prompt using Who, How long, About what, and Tone
  • I know a bug is a mistake and debugging is fixing it one step at a time
  • I can explain what a loop does
  • I can write an “if… then…” decision