Code.org Stage 13: Applying Functions in Farmer Puzzles

Coding Quote

Up until this stage, we’ve met the concept of Functions in coding a number of times.  I’ve finally figured out that Functions in computer coding is DIFFERENT than the functions we teach in elementary school math.

The first time I came across the word, “Function” in terms of Coding, the definition given to me was:

  • Function: A piece of code that can be called over and over

My response to that explanation was HUH?! After running into Functions a few more times, the light finally dawned for me when it was linked to Song Writing. We are now at Stage 13 of Code.org’s 20 Hour Coding Program.  In this stage, we’re using our understanding of Functions in a very advanced and focussed manner by APPLYING them to solve puzzles.

Function Defined and Called

Function Defined and Called

 

If you look at the top image you’ll see a block with a star in the corner.  The star indicates that this group of blocks is a Function.  The group of blocks, in this case, Fills 5.   The Function (indicated by the star) is the Function Defined.  This means that the group of blocks together executes a series of actions.  In other words, they define the function.

Underneath the starred block, you’ll see a green block that simply says, “Fill 5”.  This green block is the Function Called.  Every time you lay out this block, you’re calling the complicated Function above it to perform.

So a function needs two parts.  Somewhere in the program, you have to define the Function (the stuff above in the workspace).  Then, you have to call it (the green block below) when you need it.

 

We're making Functions

We’re making Functions

 

In the above picture, there are two Functions defined.  (We see both of them up top of the work space). We have one to Fill 5 and also one to Remove 7.  In our program, we only called “Remove 7” as that’s the only function (action) that we needed to solve the puzzle.

 

4 Solution Stage 13 Puzzle 7

I thought this above was a cute Function call:  “avoid the cow and remove 1” (green block).  Notice how big the Function Defined (up top) is and how small the Function Called (down below) is.  That’s the benefit of using a function.  We can now call on that huge piece of programming on the top over and over again easily, quickly, and without a lot of writing by just laying down a single block.

For a Function to be valuable, it has to be general enough to be able to be used in a variety of situations.   If it’s too specific, it won’t be called very often.  (Now, that’s easier said than understood.  I’ll have to wait for some examples before understanding the difference between being general and being specific in a Function.)

I finally understand what is meant by defining a Function as a “piece of code that can be called over and over again”.

I wonder if a Function will make a program run faster (more efficiently).  The more I learn, the more questions come to me.  I feel like I’m a youngster again grappling with basic language and as I make more and more connections and answer my questions, the understanding is coming.  This is a good exercise for teachers to go through—–learning like a child again.  It makes me appreciate what children go through everyday as they learn math and what second language learners must go through too.  Very humbling and a reminder to us, teachers, to be patient and understanding…

I believe I will start creating functions in my home:

  • Function 1: take off your jacket and hang it up
  • Function 2: clear your plate and put it in the dishwasher
  • Function 3: do your homework, practice your music and do your reading

I’ll give each function a different card colour.  When I want to call a function, I’ll flash the appropriate colour and save my breath!  Why didn’t I think of doing this before 😉 ?

~Vivian

 

 

About Vivian

Vivian @ChezVivian is a Canadian-born Chinese, currently living in Switzerland. She has also lived in Hong Kong and Indonesia. She holds a M.S. (focus: Educational Technology Integration), B.Ed and a B.A. and graduate studies in Kodály and Orff music pedagogy. She is an elementary school classroom generalist, but has also taught as a music specialist, ESL/EAL and also in Learning Support. Most of her teaching career was in International Schools in Hong Kong. She is excited about the IBPYP and the possibilities of using technology to Inquire. Recently, she has been looking at the opportunities that computer programming gives to put #TECHXture back into the hands of children. In other words, technology need not be just about looking at screens. It can be about building things with our hands; and computer programming levels-up what children can do with the things they build---encouraging higher thinking skills. She is a Coetail Post-graduate Certificate grad ('13-'14), a former Coetail Coach and one of the co-founders of #CoetailChat. Her blog home chezvivian.coetail.com curates her assignments for Coetail and her M.S. graduate studies about Educational Technology integration and anything else educationally-related that she feels inspired to write about. Her twitter tagline sums it up: "Mom to 4, Mentor, Educator, Musician (in that order)".
This entry was posted in 20 Hours of Code, Coding, Practical Ideas and tagged , , , , , , . Bookmark the permalink.

7 Responses to Code.org Stage 13: Applying Functions in Farmer Puzzles

  1. Hey Vivian, your article helped me out a bit. It’s not that I didn’t understand how functions work but what helped me was you explaining how to properly use the block functions. I was at a complete lost.

    I like the point you made at the end about applying these functions to real life situations, 😀

    Thank you for your help Vivian!!

    • Vivian says:

      Hi Marques! (Should I say, “salut”?)

      Thanks for taking the time to make a comment. You’re the FIRST person to say “thank you” and to give me feedback that what I’ve written about the Code.org puzzles is helpful. That’s very encouraging to me!

      Thanks again.

      Cheers

      Vivian

  2. Comy Gaming says:

    Hey there.

    Nice job, great explaining.

    However, your Stage 13, Puzzle 4 code is wrong (the IF should be first)

    • Vivian says:

      Hi

      Thanks for taking time to comment. I’m pretty sure that I made sure the puzzles ran correctly before posting the screen shot. I know that sometimes there are different ways to do things, but they still work in the end.

      Give both a try, then. 🙂 I’ll give it a go this weekend and fix the solution here if needed.

      Thanks.

  3. RA says:

    Hello. My stage 13 does not give me the option to define the function. I don’t have a star in the function like you do. How do I correct this?

    • Vivian says:

      Hi RA

      Thanks for writing and asking a specific question.

      Since the summer, Code.org has changed some of their puzzles. So, whatever notes I have on my blog might no longer apply. Please tell me which puzzle you are asking about. It is stage 13, but which puzzle? Then I can take a look at it for you.

      Vivian