Lesson 18: Functions with Artist
Overview
Students will be introduced to using functions on Code.org. Magnificent images will be created and modified with functions in Artist. For more complicated patterns, students will learn about nesting functions by calling one function from inside another.
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 with themselves and proud of their hard work.
Agenda
Warm Up (15 min)
Main Activity (30 min)
Wrap Up (15 min)
Extended Learning
View on Code Studio
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 puzzles in the lesson to find any potential problem areas for your class.
- Make sure every student has a journal.
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the Students
- Think Spot Journal - Reflection Journal
Vocabulary
- Function - A piece of code that you can easily call over and over again.
Support
Report a Bug
Teaching Guide
Warm Up (15 min)
Introduction
\Tell the class that there are two main components to using functions.
-
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.
-
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.
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 min)
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 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 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
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.
Student Instructions
"Have we met before? I'm the harvester!"
Help the harvester get to the pumpkin and pick it.
Student Instructions
"Oooh, veggies are cropping up everywhere!"
Now help the harvester pick all of the corn on the way to the pumpkin at the end.
Note: Every square on the way to the pumpkin either has 1 corn or nothing at all. Use the provided check for corn
function to make sure you get everything.
Student Instructions
Use the function to help the harvester pick the corn and pumpkins.
Each sprout will either grow one corn or nothing.
Student Instructions
"I feel so functional!"
Now there are multiple pumpkins in each patch! Look carefully at the function definitions below to figure out how to use each one.
Each sprout will either grow one corn or nothing.
Student Instructions
Great! Try your functions out on a longer path.
Student Instructions
Did you notice that there was a lot of repeated code in that last puzzle? We can save space by calling that code pick along path
and using a new function to call the other functions!
Use pick along path
to solve this puzzle again using fewer blocks.
Student Instructions
"Functions lettuce do more with less work!"
Create a function that sends the harvester down a square path to pick a single head of lettuce from the middle of each row.
Student Instructions
Try writing your function again. Is it still helpful? How can you make it work for this puzzle?
Student Instructions
This puzzle is a-MAZE-ing!*
Is your function still helpful for this puzzle?
Student Instructions
Challenge: Use everything that you've learned so far to solve this puzzle in 19 blocks or less!
Student Instructions
Solve this puzzle in 23 blocks or less.
Each sprout will either grow one corn or nothing. To find the best solution, you will need to edit the functions directly.
Student Instructions
Look at the functions defined below. What will the harvester pick?
The harvester will pick two pumpkins.
The harvester will pick all of the pumpkins.
The harvester will pick the lettuce.
The harvester will pick the corn.
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-11 - Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.
Cross-curricular Opportunities
This list represents opportunities in this lesson to support standards in other content areas.
Common Core English Language Arts Standards
L - Language
- 4.L.6 - Acquire and use accurately grade-appropriate general academic and domain-specific words and phrases, including those that signal precise actions, emotions, or states of being (e.g., quizzed, whined, stammered) and that are basic to a particular topic (e.g
SL - Speaking & Listening
- 4.SL.1 - Engage effectively in a range of collaborative discussions (one-on-one, in groups, and teacher-led) with diverse partners on grade 4 topics and texts, building on others’ ideas and expressing their own clearly.
- 4.SL.1.a - Come to discussions prepared, having read or studied required material; explicitly draw on that preparation and other information known about the topic to explore ideas under discussion.
- 4.SL.4 - Report on a topic or text, tell a story, or recount an experience in an organized manner, using appropriate facts and relevant, descriptive details to support main ideas or themes; speak clearly at an understandable pace.
- 4.SL.6 - Differentiate between contexts that call for formal English (e.g., presenting ideas) and situations where informal discourse is appropriate (e.g., small-group discussion); use formal English when appropriate to task and situation.
Common Core Math Standards
G - Geometry
- 4.G.1 - Draw points, lines, line segments, rays, angles (right, acute, obtuse), and perpendicular and parallel lines. Identify these in two-dimensional figures.
- 4.G.2 - Classify two-dimensional figures based on the presence or absence of parallel or perpendicular lines, or the presence or absence of angles of a specified size. Recognize right triangles as a category, and identify right triangles.
- 4.G.3 - Recognize a line of symmetry for a two-dimensional figure as a line across the figure such that the figure can be folded along the line into matching parts. Identify line-symmetric figures and draw lines of symmetry.
MD - Measurement And Data
- 4.MD.3 - Apply the area and perimeter formulas for rectangles in real world and mathematical problems. For example, find the width of a rectangular room given the area of the flooring and the length, by viewing the area formula as a multiplication equation with an
- 4.MD.5 - Recognize angles as geometric shapes that are formed wherever two rays share a common endpoint, and understand concepts of angle measurement:
- 4.MD.7 - Recognize angle measure as additive. When an angle is decomposed into non-overlapping parts, the angle measure of the whole is the sum of the angle measures of the parts. Solve addition and subtraction problems to find unknown angles on a diagram in real
NBT - Number And Operations In Base Ten
- 4.NBT.4 - Fluently add and subtract multi-digit whole numbers using the standard algorithm.
Next Generation Science Standards
ETS - Engineering in the Sciences
ETS1 - Engineering Design
- 3-5-ETS1-1 - Define a simple design problem reflecting a need or a want that includes specified criteria for success and constraints on materials, time, or cost.
- 3-5-ETS1-2 - Generate and compare multiple possible solutions to a problem based on how well each is likely to meet the criteria and constraints of the problem.