< Course E (2021)

Lesson 13: Functions with Artist

60 minutes

Overview

In this skill-building lesson, students will use functions with the Artist.

Purpose

One of the most important components to this lesson is providing students with a space to create something they are proud of. These puzzles progress to more and more complex images, but each new puzzle only builds off the previous puzzle. At the end of this lesson, students will feel confident and proud of their hard work.

CSTA K-12 Computer Science Standards (2017)
    • 1B-AP-08 - Compare and refine multiple algorithms for the same task and determine which is the most appropriate.
    • 1B-AP-11 - Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.

Agenda

Objectives

Students will be able to:
  • Categorize and generalize code into useful functions.
  • Recognize when a function could help to simplify a program.

Preparation

  • Play through the puzzles to find any potential problem areas for your class.
  • Make sure every student has a reflection journal.

Links

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

For the students

Vocabulary

  • Function - A piece of code that you can easily call over and over again.

Teaching Guide

Warm Up (15 minutes)

Introduction

Ask the class to think back to "Functions Unplugged: Songwriting" and recall what a function is. Open a discussion about when to use a function when writing a song.

Tell the class that there are two main components to using functions.

  1. The Declaration: Function declarations are what create a function. In a function declaration, you fill in the function with code and you give the function a name. You must declare a function before you can use it.

  2. The Call: Function calls are what makes the program run the code in the function. To call a function, you place the name of the function in your program. Make sure your function is properly defined before calling it in your program.

The class can use songwriting as an example to understand these two components. In the unplugged activity, the function containing the lyrics to the chorus was named "chorus". When we first made this function, we circled the lyrics that would go in the function. Once we named the function, we could read through the lyrics and replace the repeated chorus lyrics with a function call to "chorus".

Continue the conversation until students have a basic understanding of functions being declared and called. If students don't get to this point, make sure to do one of the bridging activities before moving into the Code.org puzzles.

Main Activity (30 minutes)

Functions with Artist

Online Puzzles

Students may benefit from writing code without functions then creating functions from the repeated code. If students don't enjoy doing this in the Code.org workspace, we recommend providing paper and pencils for students to write (or draw) out their ideas.

Wrap Up (15 minutes)

Reflection

Prompts:

  • What was today’s lesson about?
  • How do you feel about today’s lesson?
  • What are some differences between functions and loops?
  • Sketch out a drawing you made today. Can you write the code needed to create this?
  • Draw a picture you would like to create with code. Try writing or drafting the code that would make that drawing.

Extended Learning

Use these activities to enhance student learning. They can be used as outside of class activities or other enrichment.

Draw by Functions

Break the class into groups of 2-3 students. Have each group write a function that draws some kind of shape and a program that uses that function. Depending on the creativity or focus the groups, students might need to be assigned a shape to create. Once every group is done, have the groups switch programs. On a separate piece of paper, each group should draw what the program creates. The groups should then return the programs and drawings to the original group.

Did every group get the drawing they expected? If not, what went wrong? Have the class go through the debugging process and try again.

Creative Commons License (CC BY-NC-SA 4.0).

This work is available under a Creative Commons License (CC BY-NC-SA 4.0).

If you are interested in licensing Code.org materials for commercial purposes contact us.