Lesson 6: Fast Functions

Overview

In this lesson we will build on students' understanding variables by making functions that reduce the number of inputs required. These 'fast functions' allow students to practice using the Design Recipe to develop simple functions without the additional overhead of parsing a word problem.

Agenda

Getting Started

Large Group Activity (15 minutes)

Small Group Activity (20 minutes)

View on Code Studio

Links

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

For the Students

Vocabulary

  • Function - A mathematical object that takes in some inputs and produces an output.
  • Independent Variable - An input variable the is controlled by the user.
  • Parameter - A value or expression belonging to the domain of a function.
  • Variable - A reference to a value or expression that can be used repeatedly throughout a program.

Support

Report a Bug

Teaching Guide

Getting Started

Introduction

Variables in this language are immutable, which means that once they've been defined they can never be changed. This allows us to use variables to use an exact value repeatedly, but what if we wanted to make a slight change to that value each time it's used?

Suppose we wanted to create seventy-five solid-red triangles of varying size? The same frustration exist of creating seventy-five different triangle functions. There must be a better way!

Teaching Tip

This is very similar to a Variable because we are substituting one function in for another. The major difference is that Functions can receive an input from the user. Variables can only be repeated exactly and any changes made inside the code will affect all instances that variable is used. Now we have the ability to ask the user for one changing aspect of what we want and pass that information to as many functions as we want.

We can store that triangle Evaluation Block in a Function, let's call it red-triangle. Now red-triangle will ask the user for what size they would like to create keeping the triangle always green and solid, thus reducing the amount of inputs required.

Large Group Activity (15 minutes)

In this stage you will need to create some background stories to engage students into WHY we would want these Fast Functions.

Whole Class

  • Define a function blue-circle, that takes in a size and produces a solid circle of color blue on your Fast Functions - Worksheet.

Say (with enthusiasm)

Do you know my favorite Image? I absolutely love blue circles! I like small circles, large circles, and everything in between. I want to make a t-shirt with hundreds of blue circles, can you help me?

Can we use what we already know about variables? But what if I want a variety of sizes? The circle function is just too much work and no body has time for all those inputs. Can we create a function?..."

Students have been working on Contracts and basic Definitions but now we are asking something more complex and abstract. Be sure to slow down the process and focus on "What the Function Should Do". The process of making EXAMPLES is what forces the the programmer to slow down and allows them to make sure the function does what it is supposed to do.

How to Create EXAMPLES:

  • Bring down the Function-Name from the contract and ask WHY that should be the function name

  • Ask the students what input this function should take. Be sure to require them to use evidence from the Contract.

  • Ask students what output should this function DO or CALL. Many students will want to DO the math instead of having the function do the work.

    • For blue-circle remind students that if any function calls itself it wouldn't make sense like if you call yourself on your own phone. blue-circle needs to call another function to help it create this function (it calls circle which is in your Contract Log)
  • Build the second Example in the same fashion

  • Go piece by piece and CIRCLE what CHANGES and label it as a variable.

How to Create DEFINITION:

  • Go piece by piece of the example and bring down pieces.
  • Pull down your variable name from the Circled Change of the Example
  • Pull down the function the blue-circle calls and its inputs from Example. Be sure to replace anything that Changes with a variable.

Small Group Activity (20 minutes)

Breakout Groups

Put students into groups of 3 - each member of the group will represent one step of the Fast Function

  1. Contract
  2. Examples
  3. Function

Looking Forward

Students are building their understanding to eventually master Design Recipe in Stage 9. The difference between Fast Functions and Design Recipe is subtle but important that in this Stage your students focus, and master creating examples.

Their task will be to create the following three Fast Functions:

  • Define a function spot, that takes in a color and produces a solid circle of radius 50, filled in with that color.
  • Define a function average, which takes in two numbers and produces their average. (You may need to remind the students that to find the average of two numbers, they should be added together and divided by two.)
  • Suppose a company logo is a word drawn in big, red letters, rotated some number of degrees. Define a function logo, that takes in a company name and a rotation, and produces a logo for that company.
  • Levels
  • 1
  • (click tabs to see student view)
View on Code Studio

Student Instructions

Standards Alignment

View full course alignment

Common Core Math Standards

BF - Building Functions
  • F.BF.1 - Write a function that describes a relationship between two quantities.
IF - Interpreting Functions
  • F.IF.1 - Understand that a function from one set (called the domain) to another set (called the range) assigns to each element of the domain exactly one element of the range. If f is a function and x is an element of its domain, then f(x) denotes the output of f c