It’s Peanut Butter And Jelly Time In Girls Who Code

How many steps does it take to make a peanut butter and jelly sandwich? Fewer if you use functions. A function is a list of steps in a program that are all wrapped up together. Functions help programmers logically group pieces of code to make it easier to read and reuse in multiple places.

Try out the student’s instructions for creating a peanut butter and jelly sandwich below.

  1. Get (peanut butter jar)
  2. Get (jelly jar)
  3. Get (knife)
  4. Get (2 slices of bread)
  5. Open (jelly jar)
  6. Open (peanut butter jar)
  7. Spread (jelly)
  8. Spread (peanut butter)
  9. Combine (bread with peanut butter and bread with jelly)
  10. Cut (sandwich)
  11. Close (jelly jar)
  12. Close (peanut butter jar)
  13. Wipe (knife)
  14. Wipe (jelly jar)

The students at Paul Public Charter Middle School grouped repeat steps like, Spread, into functions. The students defined the function Spread as the process of scooping out the condiment from its container with a knife and smearing it onto one side of a plain piece of bread.

The students realized that this step would be repeated twice, once to spread the peanut butter and once to spread the jelly onto each slice of bread. They determined SPREAD was a function and could be reused to make their code easier to read, but how would they know which condiment to spread?

Parameters are extra details computer scientist add to their code, to change the way it behaves. Students added parameters in parenthesis to specify which condiment would be used each time the ‘spread’ function was called.

Turns out recipe instructions are just like lines of code. Can you write a code for your favorite dish? Try using functions to shorten the directions.


Our Clients

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce scelerisque nibh et neque faucibus suscipit. Sed auctor ipsum ut tellus faucibus tincidunt.

Copyright 2020 LET’S GO Boys and Girls, Inc. 501(c)(3) nonprofit EIN: 61-1612453 19 Harness Creek View Court, Annapolis Maryland 21403
Powered by Daasn