jam sandwich coding

How to Teach Coding using a Jam Sandwich

Reading Time: 4 minutes

When I first began to teach Computing, I was initially very nervous about teaching children to code. I’d never studied coding before and had certainly never programmed anything either – so I sat down and began to learn and research.

One of the greatest ideas I came across was the “jam sandwich” coding lesson.

I recently touched on this lesson during a recent article about teaching coding without using a computer, but I think it’s such a great lesson that I want to give it some more attention and bring it into the public eye a little more.

What Skills Does The Lesson Teach?

A key part of any coding lesson is teaching the children that they’ve got to be specific when giving instructions. Being specific and shortening code (or instructions) is a key part of developing their Computational thinking skills.

Too often, children will tell a BeeBot (or similar coding device) to “go over there”. But, as I always tell them, the computer doesn’t know where “over there” is and they must be more specific if they want to achieve their goal.

Aside from teaching the children to give very specific instructions, the lesson will also help children to learn to predict the outcomes of certain instructions. The children will also begin to self-correct (or debug) their code whenever it stops working the way they’d like it to.

Finally, a lesson such as this is a great way to encourage children to begin using coding-based terminology as they naturally begin to use certain words and phrases as the lesson progresses.

How Does The Lesson Go

For the purpose of this article, I’m going to break the lesson down into 4 different stages; preparation, introduction, main activity and extension. (Hopefully this will help you incorporate it into your planning with much more ease).


All you need to do to prepare for this lesson is gather a loaf of bread, some jam and a knife. I also suggest putting a desk at the front of the classroom for you to sit at whilst you teach.


jam sandwich codingI like to begin by explaining to the children that they’re going to have a lesson which will focus on teaching them coding skills. I then tell them that they need to tell me how to make a jam sandwich and I remind them to be very specific.

Further information that is useful to share is the different terminology that they will come across when studying coding. Tell the children that they’re going to be creating an algorithm (essentially their code) for making a jam sandwich. You should also tell the children about “input” and “output” because they’re two key terms which will arise in many coding lessons.

Input is basically what will go into the code (jam, a knife, bread) and the output is basically the result of the code (a jam sandwich). It’s quite easy-to-understand but it’s useful to begin using the appropriate terminology as soon as possible.

Main Activity

Sitting at the desk with your equipment laid out in front of you, begin to ask the children to give you instructions and then follow these instructions. However, there’s a slight twist as you have to follow the instructions exactly as they’re put to you.

For example, when I taught this lesson, one of the first instructions I received was to “spread the jam” and I then proceeded to scoop jam up with my hand and smear it across the table.

The scenario continued, pretty much as follows;

  • “No, I meant with a knife.”

I put jam onto the knife and spread it across the table.

  • “Spread it onto the bread”

I then smeared jam onto the bread using my hand.

  • “No use the knife and the bread”

I asked them how I should use them.

  • “To spread the jam”

I then covered both in jam and began spreading it across the table.

As you can imagine, I was covered in jam at this point – as was the table and the bread – but the children were completely engaged and gradually began to be more specific and debug their code (altering which commands they gave me to be more specific).

Soon I was receiving instructions such as:

“Cover one side of the knife with jam, lay the knife on the bread, spread the jam with the knife until you’ve covered the bread, do not go over the crust.”

This type of long, detailed instruction was honestly given to me by the children who’d quickly realised that they needed to tell me exactly what to do. Whilst I’ve typed that up as one long sentence, I should mention that the child talking to me was giving me the instructions in a step-by-step manner.

Once the children saw that they needed to be specific, they quickly helped me to make a jam sandwich.

After I’d made one sandwich, I asked them to help me make another but to help me make it using less code. At this point, children began to instruct me to “repeat” certain elements and we made another sandwich must faster.

Extensionjam sandwich coding

After the children have helped you to make the jam sandwich by giving you specific instructions, it’s time to ask them to create an algorithm showing the process.

An algorithm is basically a very specific set of instructions that can be used to reach a specific goal or bring about a specific outcome.

Ask the children to write their list of code in order – being very specific throughout the entire process. You could even ask them to shorten their algorithm by using the “repeat” command whenever possible.

Why Is This An Outstanding Lesson

This type of lesson is so useful to any teacher who is introducing the concept of coding to their students because it literally forces the children to teach themselves. Whilst you can tell them to be specific when giving instructions, the children will still initially give you very vague commands. But, by following their instructions exactly as they’re given to you – no matter how ridiculous it might seem – they’ll begin to understand that they need to be more specific and will begin to self-correct (or debug) their code.

On top of this, it’s also a fun and engaging lesson which will entertain the students throughout the entire duration. Every now and then, it’s nice for the children to experience something different and to see us, as teachers, having fun with them. It increases their enthusiasm for the subject and you can guarantee they’ll be talking about that lesson for the rest of the day and maybe even the rest of their lives.

All in all, the “jam sandwich” lesson is a great way to teach computational thinking because children are essentially teaching themselves how to debug and simplify their code, whilst be thoroughly entertained in the process.

Free Resources:
Lesson Plan

Leave a Reply