Lesson 16: Functions with Harvester

Overview

Students have practiced creating impressive designs in Artist and navigating mazes in Bee, but today they will use functions to harvest crops in Harvester. This lesson will push students to use functions in the new ways by combining them with while loops and if / else statements.

Purpose

This lesson is meant to further push students to use functions in more creative ways. By also using conditionals and loops, students will learn there are many ways to approach a problem, but some are more efficient than others. These puzzles are intended to increase problem solving and critical thinking skills.

Agenda

Warm Up (10 min)

Main Activity (30 min)

Wrap Up (15 min)

View on Code Studio

Objectives

Students will be able to:

  • Recognize when a function could help to simplify a program.
  • Use pre-determined functions to complete commonly repeated tasks.

Preparation

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

Vocabulary

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

Support

Report a Bug

Teaching Guide

Warm Up (10 min)

Introduction

At this point, your students should already be introduced to functions. Take this time to have them discuss the advantages and disadvantages of using functions in a program. Either have them pair share or discuss as a class. Try using examples of hard or easy puzzles in either Artist or Bee.

Ask the class:

  • When would you use a function?
  • Why does a function help to simplify your program?
  • Do you think functions make programming easier or harder? Why?

Main Activity (30 min)

Online Puzzles

Some puzzles will have a function pre-declared for the students to fill in. It may be helpful for the students to write the entire program without a function first, then determine where a function would be useful in the program.

It's important to make sure that every student is completing each puzzle with a dark green dot. If some of your students are struggling to simplify code and use functions, set up teams of expert students within your class to go around and answer questions.

Don't forget to provide pencils and paper to help students sketch out possible solutions.

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 about today's lesson?
  • What makes you realize a function could help your program?
  • How do while loops and if / else statements help your program?
  • The Harvester
  • 1
  • (click tabs to see student view)
View on Code Studio

Student Instructions

"Have we met before? I'm the harvester!"

Help the harvester get to the pumpkin and pick it.

View on Code Studio

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.
View on Code Studio

Student Instructions

Use the function to help the harvester pick the corn and pumpkins.


Each sprout will either grow one corn or nothing.
View on Code Studio

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.
View on Code Studio

Student Instructions

Great! Try your functions out on a longer path.

View on Code Studio

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.

  • How to Create a Simple Function
  • 8
  • (click tabs to see student view)
View on Code Studio

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.

View on Code Studio

Student Instructions

Try writing your function again. Is it still helpful? How can you make it work for this puzzle?

View on Code Studio

Student Instructions

This puzzle is a-MAZE-ing!*

Is your function still helpful for this puzzle?

  • Challenge
  • 12
  • (click tabs to see student view)
View on Code Studio

Student Instructions

Challenge: Use everything that you've learned so far to solve this puzzle in 19 blocks or less!

  • Practice
  • 13
  • (click tabs to see student view)
View on Code Studio

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.
  • Prediction
  • 14
  • (click tabs to see student view)
View on Code Studio

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

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

MP - Math Practices
  • MP.1 - Make sense of problems and persevere in solving them
  • MP.2 - Reason abstractly and quantitatively
  • MP.4 - Model with mathematics
  • MP.5 - Use appropriate tools strategically
  • MP.6 - Attend to precision
  • MP.7 - Look for and make use of structure
  • MP.8 - Look for and express regularity in repeated reasoning
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.