Lesson 16: Functions in Minecraft

Overview

Students will begin to understand how functions can be helpful in this fun and interactive Minecraft adventure!

Purpose

Students will discover the versatility of programming by practicing functions in different environments. Here, students will recognize reusable patterns and be able to incorporate named blocks to call pre-defined functions.

Agenda

Warm Up (10 min)

Bridging Activity - Functions (15 min)

Main Activity (30 min)

Wrap Up (15 min)

View on Code Studio

Objectives

Students will be able to:

  • Use functions to simplify complex programs.
  • Use pre-determined functions to complete commonly repeated tasks.

Preparation

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.

Support

Report a Bug

Teaching Guide

Warm Up (10 min)

Introduction

Content Corner

Teaching this course as a class?

Our grade-aligned CS Fundamentals courses use unplugged lessons to build community and introduce tricky computer science concepts, including functions. Check out the lesson Songwriting from Course E!

Help the class understand that functions are simply a chunk of code that has a name. Once defined, you can use that name over and over in your program to tell the computer to run the chunk of code that you assigned to it.

Bridging Activity - Functions (15 min)

Preview of Online Puzzles

Pull up a puzzle from the lesson. We recommend puzzle 9 of this lesson. As a class, work through the puzzle without using functions. Once you have gotten the solution, display it on a white board or overhead. Ask the class to point to the repeated code. Ask the class how they would simplify the program. Why can you not just use a loop?

On the white board or overhead, rewrite the program without the repeated code, but leaving one line space. In that/those line space(s), call a function. Off to the side, declare the function like the left example block in the lesson tip. Ask the class what they think the code will do now.

Open up a discussion with the class on why functions could be useful in programming. Invite students to discuss the difference between functions and loops.

Main Activity (30 min)

Online Puzzles

We recommend providing paper and pencils for students to write (or draw) out ideas. Also, if students are having trouble recognizing patterns, have them work with a partner on the harder puzzles.

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.

  • What was today's lesson about?
  • How do you feel about today's lesson?
  • What did your functions do in the programs you wrote today? How did that help you?
  • When should you use a function instead of a loop?
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!

View on Code Studio

Student Instructions

Challenge: 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.

View on Code Studio

Student Instructions

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

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-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

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.
  • 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.