# Teaching functions

How do you teach the core computer concept of functions to your students?

Share your best practices, hacks, tips and tricks here. Also feel free to share here your questions, half-baked ideas, spectacular failures and concerns about teaching loops.

In your post, be sure to tell us what grade you teach and any other relevant information about your classroom context that will help other understand how they might implement your idea.

5 Likes

Here are a few code.org Code Studio resources for teaching functions:

#### Unplugged Lesson Plans

Review āFunctional Suncatchersā Lesson Plan: Course 3

#### Code Studio Activities

Explore Course 3 functions stages:

In math we use functions all the time. If my students are advanced enough I might discuss the steps it takes to do a long division problem. Or I could do something simpler and talk about a lunch line and the function of each kitchen staffsā job.

I agree with Eric. We use the word function throughout our building in math class. Fortunately, our students have been exposed to this word before and therefore the concept is not as difficult for them to understand. I skipped the sun-catcher unplugged activity when working through this course with my students. However, if the concept and vocabulary was new to my students I would more than likely first work through this lesson.

I might try to connect functions to the current fad of making rainbow bracelets. Different patterns of bracelets each have their respective function. Or, connecting it to LEGO building where functions may be defined and used throughout the process of building a more complex structure. Functions in playing chess may be another interesting way to talk about this topic - for example, a āforkā and a āpin.ā

Functions are more than loops because they can include, not only loops, but all sorts of other commands to include , exclude, or determine.

2 Likes

I really liked being able to pull the chorus with the Little Bunny Foo Foo song and calling it as a function. I could also use the song āThere was an Old Lady who Swallowed a Fly.ā We could call a function for each animal in the song.

I also was thinking of revisiting the playground and writing instructions to move around the playground (I am going to use this for sequences as well) but then having them call functions to get on the playground equipment.

3 Likes

Functions are an interesting concept. It was easiest when I explained it like a copy of art you already created. If you draw a circle, you can continue to ācopyā that circle and use it again when you need it. Almost like a stencil or die cut.

2 Likes

I would like to try introducing functions in the gym. I love the way Chris Bosh explained how in basketball you learn the basics, like how to dribble and pass the ball, then use those skills in different ways and give them a name so everyone on the team knows how/what to do. Students could work in teams to come up with and name their own āskills,ā then teach those skills and their name to other teams. At some point students discuss the fact that they are creating functions. A student calls out a function name like ājump and jiggleā and classmates practice that function.

2 Likes

Most of my 7th and 8th grade students have already learned about functions in their math classes. For those who havenāt caught on, yet, I would use a popular (school appropriate) song. The chorus would be the function.

Really when you think about it, any recipe students already know how to make becomes a function.

Take for example, a student that is focused on mining. He knows how to create a pickaxe. He goes off and mines and eventually his pickaxe breaks. He calls the function āMake a new pickaxeā from his memory and goes off to make one. He does not have to relearn how to make it, since he has that function already stored in memory somewhere.

2 Likes

In kindergarten, first, and second grades, I would ask the students to identify tasks they complete in their daily life which have been given a name that everyone in their family or everyone in the classroom can understand. Examples might be: get dressed, brush your teeth, feed the dog, get ready for PE, pack up to go home from school. Each of those tasks is really a series of steps that we have packaged together and given a name to.

I like the idea of the sun catcher project. I think similar projects could be used at different grade levels to reinforce the concept of functions.

4 Likes

While teaching the Course 3 Functional Suncatcher Unplugged lesson last year to a group of fourth grade gifted students, one of them asked me to explain the difference is between a function and an algorithm. We discussed the similarities, but our discussion regarding what makes them different was hazy. Iād love to hear your thoughts.

1 Like

Your point that everyday tasks are functions - āa series of steps packaged togetherā - is a great one. Students would really be able to understand that. Iāve had them try to explain how to make a PB&J sandwich before. If they donāt get all the steps, it can be a mess. Same way with a function.

The way Iāve heard it explained is that an algorithm is a set of instructions for a computer to follow, and an algorithm might include a function. Functions are mini-snippets of code you might want to call again and again over many algorithms. Think of it like a āchorusā in a song, that gets ācalledā after each verse. Itās not quite a loop, but it IS a building block of a program. Not sure if I am 100% correct tho. Anyone else have a better explanation?

1 Like

I liked the ideas of using the steps for long division and songs for explaining the concept of functions to my adult students.

With 7th and 8th graders, pointing out functions as a way to shorten their code by making their own block helped. Once they made the function for the square and then used the function to draw repeated squares to make a picture, without having to use all of the usual blocks made learning functions a priority.

1 Like

I like the way of connecting the āchorusā to a function. This helped me and will help my students understand functions.

Mi piacerebbe spiegare il concetto di funzioni ai miei alunni (sia delle scuole elementari che delle medie) utilizzando un pianoforte ed utilizzando delle sequenze di tasti bianchi , tasti neri , pause , cluster di note e battiti di mani . Utilizzando la tastiera del pianoforte gli alunni avrebbero unāampia possibilitĆ  di utilizzare suoni diversi.
Skill 1:
Skill 2
Program: Skill 1 Skill 1 Skill 2

Iād say that a function is basically an algorithm with a name.

Going farther, Iād say that we give it a name so that we can tell the computer to do that algorithm using one word, instead of having to type out all of those lines of code every time we want that algorithm to happen.

Going even farther, Iād say that a function can be algorithms within algorithms (or functions within functions). For example: `eatBreakfast` might be a function that includes the functions `setTable`, `makeToast`, and `pourCereal`, and also algorithms for walking from one part of the kitchen to another, in between those functions.

3 Likes