How long do you spend teaching variables? I just spent three weeks.

In my grade 7-8 CS class, variables are the first major topic we tackle. I was really determined to get every kid in the class to a place where they could write a program, on their own, from scratch. This is a tall order. Even when I was a TA for a college CS course (years ago, but still), I know I had students that got to the end of the semester and never once created their own program. I find this sad, as creation is a really empowering activity for anybody. I really, really want every single one of my kids to be able to do it.

I think we’re almost there. But looking back on my timeline, we’ve spent three weeks – THREE WEEKS! On just the topic of variables and operations.  I don’t assign homework and do a lot of discussion and partner work – but I’m wrestling with what we could have done differently, or if this is just how things go in middle school.

This is how it went down.

Lesson 1:  Feb. 18. A pair-programming activity in which kids had to create reflections, translations, and rotations on a coordinate plane using a skeleton program. They learned about the coordinate plane, and they could do the activity using variables or not using variables. I wanted them to investigate the structure of variables without a lecture first.
After the programming activity, we processed as a class what coordinate rules produced the different transformations, and how the coordinate plane on a computer’s canvas is different from the one you use in math class.
Activity 1: Reflection
Activity 2: Rotation
Activity 3: Translation

Lesson 2: Feb. 24. I assigned the students into pairs to specifically dive into the topic of variables. I delivered some notes on the vocabulary of declaring a variable, assignment, and substitution. We watched a video on pair programming from Code.org.
Pair Programming video

As a class, we made lists of the important do’s and don’t’s of pair programming. The kids assigned roles – driver and navigator – and I first  gave them a direct lesson on how to write a program that would use variables to find area of a rectangle and draw that rectangle. I then released them to work with their partner on using variables to draw an ellipse and calculate the area of the ellipse.
Area of Shapes lesson

This lesson is really more on identifying patterns and structure than it is about understanding variables, but the patterns are useful in learning a new language.

Lesson 3: March 2. I first gave a set of notes on math operators. Students were already familiar with +, -, /, and *.  We introduced the floor() function – I showed some examples of floor() and had the students hypothesize what the function did. I also introduced the modulo operator, which in JavaScript looks like a %.  This one was harder for students to guess.  We talked about how modulo is useful when doing an operation such as making change, and what operations are used when you walk into a bank with a jar full of pennies and want to get a small number of bills and coins back.
I put the kids into pairs and assigned them the task of using variables to write the “Planet Zorg” program. They did nicely switching off between driver and navigator, but this program was really difficult for them. It took most of the class period, and most groups did not finish independently.

Planet Zorg Starter Program

Lesson 4: March 4. I wanted students to move from working in pairs to working independently. I assigned them two tasks:

1) Complete the “Funky Frog” challenge on Khan Academy. An additional challenge was to create a variable for the size of the frog and use it to scale the shapes.

2) Write a program that uses three “input” variables – the cost of an item, the percent discount, and the percent tax – and calculate the final cost of the item after discount and tax.
Slides on Discount and Tax program, with “hints”

About half to two-thirds of the class had a great deal of difficulty completing the task without hints, and the reasons were related to not understanding how to calculate discount and tax, or not understanding variables, or often – both. I blogged about this in a previous post.

Lesson 5: March 6. Some of the kids were done with the discount and tax program. Some were not. I split the class into two groups. Those who were done with the discount and tax program, who I felt were ready to move on, could take the variables quiz.  Those who were not would work in a smaller group with me to understand and finish the discount/tax program. The variables quiz was fairly straightforward for the half of the class that was ready for it.
Variables Quiz: Car Economy

Lesson 6: (SIX LESSONS ON VARIABLES, PEOPLE!) March 10. Students who had just finished the tax/discount program needed to take the quiz. For one of my classes, this was not too bad and almost everyone was able to finish the quiz and demonstrate they had learned about variables. My other class started this during our standardized testing block and had shortened testing time. This class also had a larger portion of kids who didn’t understand the tax/discount program, and a larger portion of absences – lots of factors working against us. Most kids did not finish the quiz.  I really, really hope to get this done before spring break!!
For the kids that finished the quiz and were ready to move on, I paired them up and had them do an inquiry activity on boolean expressions – which is a post for another time.

I bring all of this up because it’s been just shocking how much time I’ve spent on this one really basic topic. When I was in college, this whole topic took an hour and then we had an assignment to complete for the next week. If you didn’t understand the first week’s assignment, you were completely sunk because everything from that point on built from that first week’s lesson.

So I really want, really need the kids to be able to use variables flexibly and independently, because if they don’t, they will not be able to program independently and they will just be going through the motions for the rest of the semester.  High school CS isn’t going to go any slower than this. Failure just is not an option. There are a ton of reasons why it’s taking this long, but I really am hopeful that the investment will pay off down the road.