Lesson 15: Harvesting with Conditionals

Overview

Students will practice while loops, until loops, and if / else statements. All of these blocks use conditionals. By practicing all three, students will learn to write complex and flexible code.

Purpose

Practicing the use of conditionals in different scenarios helps to develop a student's understanding of what conditionals can do. In the previous lesson, students only used conditionals to move around a maze. In this lesson, students will use conditionals to help the farmer know when to harvest crops. New patterns will emerge and students will use creativity and logical thinking to determine the conditions where code should be run and repeated.

Agenda

Warm Up (5 min)

Main Activity (30 min)

Wrap Up (15 min)

View on Code Studio

Objectives

Students will be able to:

  • Nest conditionals to analyze multiple value conditions using if, else if, else logic.
  • Pair a loop and conditional statement together.

Preparation

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

Vocabulary

  • Condition - Something a program checks to see if it is true before allowing an action.
  • Conditionals - Statements that only run under certain conditions.
  • Loop - The action of doing something over and over again.
  • Repeat - To do something again.
  • While Loop - A loop that continues to repeat while a condition is true.

Support

Report a Bug

Teaching Guide

Warm Up (5 min)

Introduction

Students shouldn't need as much of an introduction to concepts today because they have had practice with them in the previous lesson. Instead, you can share the story of the harvester.

The harvester is trying to pick crops like pumpkins, lettuce, and corn. However, the farmer has forgotten where she planted these crops, so she needs to check each plant before harvesting.

Main Activity (30 min)

Online Puzzles

Students will continue to work with if / else statements, while loops, and until loops. These puzzles are a bit more challenging, though, so encourage students to stick with them until they can describe what needs to happen for each program.

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?
  • How can you see conditionals being useful in programs?
  • What if people only spoke in if/else statements? What would be some advantages and disadvantages of this?
  • The Harvester
  • 1
  • (click tabs to see student view)
View on Code Studio

Student Instructions

"Corn you help me harvest today?"

Help the harvester check her row of corn to see if anything is ready to pick. Use conditionals to look at each sprout. Every stalk will have either 0 or 1 pieces of corn ready to harvest.

View on Code Studio

Student Instructions

"Lettuce collect both crops from this row!"

This garden is all mixed up, it has both corn and lettuce!

Help the harvester pick the items that are ready for harvesting. Each plant will have either one corn or one lettuce.

View on Code Studio

Student Instructions

"Corn, lettuce, AND pumpkins! Help me harvest them all."

Each plant will have either one piece of corn, one head of lettuce, or one pumpkin.

View on Code Studio

Student Instructions

"Gosh! Now the lettuce is growing in clusters!"

The harvester wants to pick everything from her lettuce garden. Each plant will now have more than one head of lettuce on it, so the harvester will need to keep picking while there is still lettuce growing.

(Remember: This garden only has lettuce!)
View on Code Studio

Student Instructions

"What a bountiful crop!"

This field has clusters of corn and lettuce growing together -- with one pumpkin at the end. Can you harvest everything?

View on Code Studio

Student Instructions

"Let's take this one step further!"

Can you figure out how to pick the pumpkin? Make sure to collect all of the corn along the way!

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

Student Instructions

Challenge: Collect all of the corn and lettuce, then pick the pumpkin.

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

Student Instructions

Collect all of the corn and lettuce, then pick the pumpkin.

View on Code Studio

Student Instructions

Collect all of the corn and lettuce, then pick the pumpkin.

  • Prediction
  • 11
  • (click tabs to see student view)
View on Code Studio

Student Instructions

The sprouts in this puzzle will be either corn or lettuce.

Take a close look at the code below. What will happen after you click "Run"?

The harvester will collect all of the crops.

The harvester will not pick any of the crops with the path she is taking.

The harvester will pick all of the crops, except the pumpkin.

I don't know.

View on Code Studio

Student Instructions

The pumpkins mark the place where you should turn right. Otherwise keep going forward, but remember to collect all of the lettuce or corn along the way.

Each hidden crop has only one corn or lettuce.

View on Code Studio

Student Instructions

"It's a very varied vegetable maze!"

Turn right at pumpkins, turn left at lettuce. Collect everything to complete the level.

Standards Alignment

View full course alignment

CSTA K-12 Computer Science Standards (2017)

AP - Algorithms & Programming
  • 1B-AP-11 - Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.