Teaching Kids to Code: Day 2

This week, I am teaching a youth summer enrichment course for coding in Java.  You can read about my first day here.

Day 2 went much more smoothly than Day 1.

When I teach, at least towards the beginning of a course, I take roll in GTYK sort of way.  It's great to learn a bit about the students, but it's also great to gauge how comfortable the students are with me as a teacher.  Am I creating the right atmosphere for learning? Do they trust me? etc.

Anyway, so today I told them that when I called their name they should say "Here" and share their scariest memory.  The first kid wouldn't share something, and I thought, "hmm".  Then, with the second kid there was a dramatic pause during which I was wondering if I had picked the wrong thing to ask them.  Just as I was about to back off and ask the students a different question, he said that his first time jumping from 20 feet down to the ground while practicing parkour was his scariest memory.  You do parkour? Cool! For how long?

Most of the kids opened up after that, and I was able to share some scary stories of my own, like getting pushed off the diving board when I was 4 or accidentally hitting my son with a small tree causing him to tumble down a mountain side when he was 3.

After this, we did a Code n' Tell.  I guess every kid likes showing off, but there is something rewarding about showing off what you were able to make a computer do.  We talked about the changes that students had made to the number guessing program outside of the project objective.  One student added the concept of a maximum number of tries before the player lost the game.  I asked the class how they might implement such a feature, and another student described it to the class and I wrote down the appropriate code on the board, asking the students for feedback on syntax, etc.  I asked the original coder if the class got it right, and he added a couple of improvements.  It was great to see the gears turning.

Next was a Bug Hunt.  To review the concepts from the previous day, I wrote a few lines of code on the board that had some typos that had to do with what we learned yesterday.  For example, I wrote:


int guess = takeGuess();
if ( guess > 10 )
  System.out.println("Woah! That's a big number!")


The students correctly pointed out the missing curly braces.  (I told them that they were always necessary; for now, I want clean, legible code!)  They also noticed the missing semi-colon on the end of the System.out.  We reviewed for a few minutes why some lines in Java have semi-colons and others don't.  This was tricky for the students to grasp at first.  For the time being, most of the students just know that semi-colons don't come after curly braces.  A few of the students comprehended the idea that if, for, and while are like "multi-statements" or statements that have children.  I'll need to re-enforce that later on.

The next set of bugs looked like this:


number = 10;
if ( number > 10 ) {
  system.out.println("The number is: " number);
}


The kids right off the bat noticed the missing type reference; line 1 needs an "int" in the front.  They also quickly noticed that something was wrong with the string literal, but it took a little bit of coaching to realize that it was a missing + sign.  Last, they noticed (though this one doesn't translate as well on the board) that the "system" needed to be "System".  Not bad.  The kids asked questions like "Are there any other places in Java where you use the plus sign like that?" And "What does the 'int' mean?" Perfect.

With those out of the way, we pulled open Greenfoot.  No matter how many times I say something, there is a kid or two that doesn't listen or that runs into problems, so opening Greenfoot and getting the first scenario open took a few minutes.  "Where is Greenfoot?", "I don't have that scenario", "My scenario doesn't work", etc., etc.  One student had accidentally removed all the code from the inside of one of the Actors, and that had to be restored.  Getting everyone onto the same scenario took about 5 minutes.

After that, though, it was a bit of managed chaos for the next two hours.  In case you are familiar with Greenfoot, we started with the Wombat scenario.  I showed them how to run the scenario, how to invoke methods on the Actors arbitrarily, how to change the underlying Java code.  In the process, we talked about what was good or bad about the scenario and what we could do to improve it.  As the students gave suggestions, I wrote them down on the board:
  • Have the wombats be smarter about turning so they can get the leaves on the inside
  • Have the wombats die if they don't eat leaves soon enough
  • Have the wombats be controlled by the user through the keyboard instead of the Wombat making its own decisions
  • Make an enemy to the wombat that chases after it
All great ideas.  In fact, the last two are in my lesson plan for Thursday, so that's great.  And, in fact, the first and the second (at least in spirit) were in my lesson plan for today.  Awesome.

We started off with the second one.  I mentioned that we should have it go both ways; the wombat should somehow get healthier the more leaves he eats.  How should we represent that? I mentioned The Very Hungry Caterpillar, and one kid latched onto the idea that we should make the wombat bigger every five leaves that he eats until a certain point when he explodes and makes three new baby wombats.  (I do have a class almost entirely of teenage boys.)  Great idea, let's do it!

The experience was really electric.  We talked about the math of "every 5th leaf" using the modulo operator.  We talked about method invocation and why we need parentheses even when there are no parameters.  We talked about newing up an object (the new babies).  From a Greenfoot standpoint, we used several elements of the API:  We scaled up the image as the wombat ate more leaves, we "exploded" him (removeObjects) and added new babies (addObject).

The biggest problems that the kids were having was with curly braces and semi-colons.  These are just hard, period.  We talked for a bit about keeping the code clean and keeping curly braces lined up.  The other subtle problem was that some of the kids didn't quite comprehend the idea that if the condition in an "if" statement isn't met that the program won't run the code on the inside.  Several kids had at some point or another something like this:


if ( leavesEaten == 5 ) {
    ... get bigger ...
    if ( leavesEaten == 25 ) {
       ... explode and make babies ...
    }
}


"Mine isn't exploding", each would say.  I'm sure you see the problem that after the fifth leaf is eaten, it never gets into the outer if block, let alone the inner if block.  Of those kids a few quickly realized what was going on.  One or two of the kids just changed it how I told them to and it felt like a bit of magic to them.

We got side tracked on the "death" objective because many students were complaining about how long it took to add leaves to the game.  So we shifted gears and talked about how to do random numbers and how to use those to generate random leaves.  This was cool because we started to get into population modeling, at least in concept.

The last objective we didn't have much time for, but we tried anyway.  A couple of the kids got the Wombats eating all the leaves by the end, though, by not always hugging the wall like it does.

Some kids added niftiness, so we ended the class with a Code n' Tell.  One student added Spiders onto the board.  If a Wombat ran into a Spider, the Wombat died.  Awesome! We talked briefly about what he had to do to get that to work.  Another student found an Explosion actor from another scenario and added that to his scenario so when he placed an explosion randomly in his World, it would destroy all the Actors in its wake.  Great!  Another student hadn't quite figured out the smart turning, thing, but he'd make the Wombats do a little dance.  :)

Overall, I think the students had fun with it and left with a higher level of confidence in their coding abilities.

I can't wait for Thursday!

Josh Cummings

"I love to teach, as a painter loves to paint, as a singer loves to sing, as a musician loves to play" - William Lyon Phelps

1 comment:

  1. That is so awesome! You sound like a great teacher. Thanks so much for posting this. It has given me several ideas.

    ReplyDelete