• If peanut allergies are a concern, particularly in classroom settings, substitute sunflower butter.

This messy but always fun Rosie Explores activity introduces kids to algorithms, functions, loops, bugs and the need for specificity in coding as they attempt to “code” a robot!

It’s best to do this with at least three people – a programmer, a robot, and a scribe to record the algorithm (the steps needed to complete the peanut butter and jelly sandwich). That way you can look back at each line of code and see where there may be “bugs” or errors in your instructions. You can also discover how you might create functions and loops to repeat steps that need to happen over and over again! This activity works great in larger classrooms too as you can designate groups of students to be scribes and programmers.

As this is an introductory coding activity, it includes some computing terms that might be new to kids:

Algorithm – a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.

Function – a block of organized, reusable code that is used to perform a single, related action.

Loop – a control flow statement for specifying iteration, which allows code to be executed repeatedly.

Bug – an error, flaw or fault in a computer program or system that causes it to produce an incorrect or unexpected result, or to behave in unintended ways.

Ready to become a robot and make a PB&J? Watch the video for an overview, gather the materials listed at the right, and follow the instructions below!

Required Materials

  • peanut butter
  • jelly
  • loaf of bread
  • knife
  • plate
  • paper
  • pen, pencil, or other writing tools

Step-By-Step Instructions

Step 1

Designate who will be the robot, programmer(s), and scribe(s).

Step 2

Don’t prepare for the activity! Leave the bread in the package, and the lids on the containers of the peanut butter and jelly. Place these items along with a plate and knife in front of the robot.

Step 3

Have the robot transform! Make sure the programmer and scribe know that the robot has no prior knowledge related to sandwich making. It recognizes the materials, but will only do exactly what the programmers tell it to do!

Step 4

Ask the programmer for the first step. Make sure that the robot follows these instructions literally, and watch as hilarity ensues! The scribe should be writing the steps as well, recording exactly what the programmer says.

Step 5

Continue giving the robot instructions and writing the steps until it has produced some semblance of a sandwich. Then have the robot transform back into a human, and discuss why it was so hard to get the sandwich made.

Step 6

Finalize the best version of the sandwich-making code with the scribe, and figure out which steps could be repeated using functions and loops.