< Course E (2022)

Lesson 10: Functions in Minecraft

70 minutes

Overview

In this skill-building lesson, students will begin to understand how functions can be helpful!

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.

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:
  • Use functions to simplify complex programs.
  • 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 every student has a reflection journal.

Links

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

For the teachers
For the students

Vocabulary

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

Teaching Guide

Warm Up (10 minutes)

Introduction

Display: Show “Reflect” slide

Reflect: What is a function and how do you use it?

Discussion Goal: Make sure students 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.

Vocabulary

Display: Show “Vocabulary” slide

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

Bridging Activity - Choose One (15 minutes)

Display: Show “Bridging Activity” slide

This activity will help bring the unplugged concepts from "Functions Unplugged: Songwriting" into the online world that the students are moving into. Choose one of the following to do with your class:

Unplugged Activity Using Some Blockly

Pick a song to play that the students enjoy and print out the lyrics. You can use the same song from "Functions Unplugged: Songwriting." Break your class into groups or pairs. Pass out the printed out lyrics (including the repeated chorus) and the basic function blocks from *Unplugged Blocks to each group or pair of students. See lesson tip for details.

Ask the students to cross out any part of the song that can be made into a function (the chorus is a good example) and put it into the function blocks provided. Students should fill in the function declaration with a function name and the words of the repeated lyrics. Once the function declaration is done, ask the students to fill in the function calls and place them on top of the crossed out lyrics.

Teaching Tip

Function blocks:

The block to the left is a function declaration, a block that students will name and use to fill in the function. The block to the right is a function call, a block that makes the function code run. Students will need multiple of the function call blocks.

Once every group or pair is done, ask the class where they put their functions and why. Did everyone make the same function? How often is the function repeated?

-Or-

Preview of Online Puzzles

Pull up a puzzle from the lesson. We recommend puzzle 9. 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: Why can't you 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 minutes)

Functions in Minecraft

Display: Show “Minecraft - The Agent” video

Teaching Tip

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.

Display: Show “Level 2-3 - Skill Building” slide

Display: Show “Minecraft - Repeat Loops” video

Display: Show “Minecraft - Functions” video

Display: Show “Minecraft - Congratulations” video

Display: Show “Level 16 - Free Play” slide

Wrap Up (15 minutes)

Reflection

Display: Show “Reflect” slide

Reflect:

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