Computer Science
Grade 2
20 min
The Peanut Butter and Jelly Algorithm
Students write instructions for making a PB&J sandwich. Emphasize detail and order.
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Explain that an algorithm is a list of steps.
Write a simple, step-by-step algorithm for a daily task.
Identify the correct order (sequence) for instructions.
Find a mistake (a bug) in a simple algorithm.
Fix a mistake (debug) in a simple algorithm.
Understand why instructions for a computer must be very specific.
Can you teach a robot to make a sandwich? 🤖 Let's find out!
We will learn how to give perfect instructions. These instructions are called an algorithm. This helps us think like a computer programmer!
Real-World Applications
Following a recipe to bake cookies 🍪
Building a LEGO set using the instructions 🧱
Your morning routine to get ready for school ☀️
Playing a board game by the rules 🎲
2
Key Concepts & Vocabulary
TermDefinitionExample
AlgorithmA list of steps to finish a task. It's like a recipe! 📜The steps to brush your teeth: get toothbrush, put on toothpaste, brush, rinse.
InstructionOne single step in your algorithm. Each one tells you to do one thing. ☝️A single instruction is: 'Get two slices of bread.'
SequenceThe order of your instructions. The steps must be in the right order to work! ➡️You must put on your socks *before* you put on your shoes.
ProgramThe whole set of instructions for a computer or robot. 💻Your entire peanut butter and jelly algorithm is a program for a robot chef.
BugA mistake in your algorithm that makes it not work. Oops! 🐞An instruction says 'Spread jelly on the table.' That's a bug!
DebuggingFinding and fixing the bugs in your algorit...
3
Core Syntax & Patterns
Rule 1: Be Super Specific! 🎯
Instructions must be very, very clear.
Computers don't have brains like us. They only do exactly what we tell them. Don't say 'get bread.' Say 'get two slices of bread from the bag.'
Rule 2: Order Matters! 🔢
Steps must be in the correct sequence.
You can't put the sandwich together before you spread the peanut butter. The order is very important for the algorithm to work.
Rule 3: One Step at a Time. 🚶
Each instruction should only do one small thing.
Don't say 'Get the jelly and spread it.' Make it two steps: 1. Get the jelly jar. 2. Spread the jelly on one slice of bread.
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
Your algorithm uses only one knife. A bug happens: there is peanut butter in the jelly jar. How could you change the algorithm to fix this bug, still using only one knife?
A.Use a spoon for the jelly
B.Spread the jelly first, then the peanut butter
C.Wipe the knife clean after spreading the peanut butter
D.Get a second knife
Challenging
How could you make the instruction 'Spread peanut butter on one slice of bread' more precise for a robot?
A.Use the knife to cover one side of a bread slice with a thin, even layer of peanut butter.
B.Plop some PB on the bread.
C.Just put the peanut butter on the bread.
D.Make the bread yummy with peanut butter.
Challenging
You want to create a 'master' algorithm that can make a PB&J OR a ham sandwich. What is the best, most general first step for this flexible algorithm?
A.Get peanut butter
B.Get ham
C.Open the bread bag
D.Choose which kind of sandwich to make
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free