Stage 15: Defining Functions and adding Parameters

Stage 15 Defining  Functions


We are now onto Stage 15 of this 20 stage learn to code program by

Click here to see my Function pictured above run.

Up until this stage, the definition of Function was this one:

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

In this stage (Stage 15) , the definition for Function is this one:

  • Function: a sequence of instructions

If you look at the image at the top of this blogpost, you will see that there are two Function Definitions:

  • To draw a square
  • To draw a circle

We know that it is a Function Definition because it has a star in the corner of the block.  Inside the Functions are sequences of instructions.  Having these two sequences of instructions is not enough.  We still need to “call” the Function.  We call it (activate it) by dragging the Function into the program space.  In other words, if we want to draw a square, we drag out the block that says “Draw a Square”.  This is what I have done (see the green block above).

We don’t want to draw a circle so we stop there.  If we wanted to draw a circle, we could have to drag that block out.

In Stage 15, we are learning to define functions by doing more Artist puzzles.  That means we are trying to figure out and insert the little bits of instructions that appear inside the starred block.


Click to see my little program to draw a Triangle run.  You can see the code below:

Draw a Triangle


We now move on to working with multiple functions and stacking them in sequence to draw a complex design.  Click here to run what is shown below.

Multiple Functions


The next step is to name my own Function Definition and to put the sequence of instructions inside it.  In this case, I named my Function Definition “Draw a House” and then I pulled out the block that said “Draw a House”.

Click here to run it and take a look at the program below:

Draw a House Function Definition

Draw a House Function Definition


I think we’ve spent quite a lot of time on Functions.  The next set of puzzles in Stage 15 is to put in Parameters.

  • Parameters:  things you add to the Function so you can customize it

Up until now, we dragged out a “Draw a Triangle” block when we wanted a triangle.  We probably want to specify the colour of the triangle or the size of the triangle so that we have more control over what we are drawing.  Adding in these customizations is called passing in a Parameter.  (“Colour” and “Size” are the variables in this case.)

If you look at the image below, you will see one Function with the word “with Length” near the star.  It’s the “Draw a Square” block.  The “with Length” is allowing us to put in a parameter that will customize the length.  The other block called “Draw a Triangle” doesn’t allow for Parameters.  Our job for this puzzle is to change the “Draw a Triangle” block so it can take Parameters.  In this case, we click on the star in order to do this.

Adding Parameters

Adding Parameters

Click here to make my program run.

See the image below.  I’ve changed my “Draw a Triangle” block so it can take Parameters.

Putting in a Parameter

Study the differences between this image and the one above to see how I changed it to take Parameters


The rest of the puzzles in Stage 15 are exercises needing more and more Function Definitions and we have to customize these Function Definitions so there are variables and so the variables can take Parameters.  Then, we drag out the Function blocks to activate the Function Definitions and actually specify the number (Parameter) we want.

As always, it’s much easier to do than to explain.  Everything has been scoped and sequenced very well so I’ve never felt like the increments in learning were too big.  Like Goldilocks,  they have all been “just right”.


Click to run the program below:

Three Houses

Three Houses Program
Java Script for Three Houses

This is the Java Script equivalent for the Three Houses program above.



Click to Run the program below and I’ve used a counter (block in pink) so I don’t have to write so much coding:

Using the Counter Block (the pink one)

Using the Counter Block (the pink one)


I’ve now written 1,390 lines of code since the beginning of the 20 Hour “Hour of Code” course.  Wheew!


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 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, Course 5- Putting Pedagogy into Practice, Practical Ideas and tagged , , , , . Bookmark the permalink.

4 Responses to Stage 15: Defining Functions and adding Parameters

  1. Crazyhead says:

    I really like this website

    • Vivian says:

      Thanks for your praise, Crazyhead. This website is actually for teachers to learn about the background behind the different stages, so they are better equipped to help their students. There have been a number of students writing me and asking me for the answers to the puzzles, but my intention was never to give out answers. 🙂 I hope the background information helps you a bit to figure out the puzzles.

  2. Danny says:

    Hi Vivian,

    I really love your website. I’m looking forward to seeing more.
    Take care

    • Vivian says:

      Thanks for taking the time to send encouragement. It means a lot. I think some of my information is getting dated though. I noticed that some of the puzzles from the 20 Hour program from are different from when I played them this past December/January. They’ve probably changed some puzzles to adjust for any thing they’ve learned since launching the program. Hopefully some of my information is still relevant.