Please enable JavaScript to use CodeHS

Computer Science and Digital Literacy

Problem Solving With Computers

Every coder makes mistakes. Practice finding the bug in a simple sandwich recipe.

Beginner ~8 min Elementary
The Big Idea

Big problems become small steps

When a problem feels hard, computer scientists break it into smaller pieces. This makes each piece easier to solve. Then they put the pieces back together.

If something goes wrong, computer scientists look at each step to find the mistake. Finding and fixing mistakes is called debugging.


How It Works

How to solve a problem like a computer

  1. Understand what you want to happen.
  2. Break it into small steps.
  3. Try the steps one at a time.
  4. Debug: find the step that does not work and fix it.
  5. Try again until it works.

Every coder makes mistakes. The best coders are good at finding and fixing them.


Interactive

Debug the sandwich

One of these steps is out of order or missing. Click the step that is wrong.

  1. Get two slices of bread.
  2. Put the two slices together.
  3. Spread peanut butter on top of the closed sandwich.
  4. Cut the sandwich in half.

Your Turn

Check yourself

Tell a friend the steps to make a peanut butter sandwich. What step could be wrong if the peanut butter ends up on the outside?

Sample answer: The wrong step is putting the bread together before spreading the peanut butter. You need to open the sandwich first.


Check Yourself

Quick quiz

1. What is debugging?

2. What do you do when code does not work?

3. Why break a big problem into small steps?

Keep learning

You are a problem solver now. Next, find out how to start with CodeHS.

Part of the Computer Science and Digital Literacy series.