Lesson 30: Functions with Parameters in Bee

Overview

This lesson features the bee environment, and continues along the concept of functions with parameters from the previous Artist stage. Students will practice writing and using functions to follow complex paths and collect patterns of nectar and honey.

Purpose

Functions are incredibly important in computer science for many reasons. The ability to break down and categorize code will become immensely important as the programs your students write become more and more complex. Functions with parameters require an extra level of skill. Using functions with parameters teaches your students to recognize when a function is needed and if that function can be generalized enough to be used for multiple cases. This lesson, along with the previous lessons on functions with parameters, builds a strong set of critical thinking and problem solving skills.

Agenda

Warm Up (15 min)

Main Activity (30 min)

Wrap Up (15 min)

View on Code Studio

Objectives

Students will be able to:

  • Recognize repeated tasks that need to be specialized on a case-by-case basis and create functions to efficiently run these tasks.
  • Use pre-built functions with parameters to complete commonly repeated tasks.

Preparation

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the Teachers

For the Students

Vocabulary

  • Function - A piece of code that you can easily call over and over again.
  • Parameter - An extra piece of information passed to a function to customize it for a specific need

Support

Report a Bug

Teaching Guide

Warm Up (15 min)

Introduction

Before class, set up a couple of paths in the classroom for students to walk on. Make sure the number of steps is obvious either using tape or cut outs of footprints. These paths should vary in length.

Gather the class together and note that there are different paths to walk down, but you don't want to have to write separate functions to walk down each one.

Instead, on an display the class can see, write or display the following

FUNCTION - "path", PARAMETER - "step"

  • repeat "step" times:
    • walk forward

Ask the class if they know what the code you wrote means. Tell the class that instead of writing a unique function for each path, you wrote a function that can be customized to the length of the path.

This was done by declaring a function, "path", then giving it a parameter, "step". The variable, "step", can be used to hold the number of steps for each path.

Play with the function for each path, having a volunteer name the number of steps in a path and another volunteer walking down the path according to the code.

Main Activity (30 min)

CSF Express Course - Website

As the class works through these puzzles walk around and ask the following questions to each student.

  • Are you using a function? Why or why not?
  • If you aren't using a function, do you think a function could be helpful here?
  • If you are using a function, are you using a parameter? Why or why not?
  • If you aren't using a parameter do you think a parameter could be helpful here? Why or why not?

Sometimes the students won't need to use a function or a function with parameters, but they should always know why they are doing what they are doing.

Wrap Up (15 min)

Journaling

Having students write about what they learned, why it’s useful, and how they feel about it can help solidify any knowledge they obtained today and build a review sheet for them to look to in the future.

Journal Prompts:

  • What was today’s lesson about?
  • How did you feel during today’s lesson?
  • Do you think parameters are helpful in code?
  • When did you use a parameter and how did it change the way you wrote the rest of your program?

Standards Alignment

View full course alignment

CSTA K-12 Computer Science Standards (2017)

AP - Algorithms & Programming
  • 1B-AP-08 - Compare and refine multiple algorithms for the same task and determine which is the most appropriate.
  • 1B-AP-09 - Create programs that use variables to store and modify data.
  • 1B-AP-11 - Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.