The Variable Coding Challenge in Scratch
In my 6th grade Web 2.0 class, I have the pleasure of spending 8-10 classes with them learning computer programming. Many kids have a little experience with Scratch at this point, through their elementary tech classes. I like to build on this experience by adding on some more advanced coding topics.
One CS topic we cover is variables. Kids learn that a variable is a storage location in the computer for information, and that variables must be declared, assigned, and then they can be substituted into expressions. We practice first by analyzing a program and extending it.
Students work with me to add an extra variable, “weight of pet”. Then we add the weight of the pet to your weight on earth, divide the total by 6, and tell you the weight of both you and your pet on the moon.
Before introducing their work time assignment, we watch a video about pair programming. I like this video and think it’s fun, cute, age appropriate and to the point.
We go over the norms of pair programming, I partner the kids up, and give them an assignment. They can choose one of the four variable challenges listed here. They must create a Scratch program that uses variables, “ask” blocks, and math operations to complete the challenge.
Challenge 1: Patrick and Spongebob are going shopping. Spongebob needs snail chow and Patrick needs Krabby Patties. Each box of snail chow costs $2.19. Each Krabby Patty costs $6.25. The cashier should ask how many boxes of snail chow and how many Krabby Patties they want, and store the amounts as variables. Tell Spongebob and Patrick how much their total bill is.
Challenge 2: Fluffy is getting new carpet installed in her apartment. She knows the length and width of her family room and bedroom. When she goes carpet shopping, she finds out the carpet she wants is $3.50 per square foot. Also, there’s a $250 installation fee. Fluffy should use variables for the length and width of the family room, and calculate the total cost of the carpet.
Challenge 3: Kanye has a rectangular hot tub, but he’s under water restrictions, so he needs to keep track of how many gallons of water he’s using. Kim knows there are 231 cubic inches in one gallon. She should ask Kanye for the length, width, and height of his hot tub and store them as variables. Then, she should calculate how many gallons are needed to fill the hot tub.
Challenge 4: Neville and Hermione are helping Hagrid take care of his reptiles. His lizards eat 7 crickets each day. The bearded dragons eat 18 crickets each day. The juvenile Norwegian Ridgebacks eat 95 crickets each day. The kids need to purchase a week’s worth of crickets. They should ask Hagrid how many lizards, bearded dragons, and Norwegian Ridgebacks there are, and store those as variables. Calculate the number of crickets needed for a WEEK and say how many need to be bought.
The kids found the challenges very engaging! They worked hard and the pair programming protocol worked overall quite well for them.
Their programs were adorable, clever and fun. Here were some of them!
The Patrick / Spongebob Challenge:
- These students laughed and laughed at their funny sound effects and animation.
- A little different programming solution that re-uses the input variables. It works well!
The Fluffy Carpet Challenge:
- These kids worked so hard designing the perfect costumes for Fluffy the rock and the carpet salesman. https://scratch.mit.edu/projects/76306458/#player
- These kids spent a lot of time recording audio and their program is absolutely amazing. At press time, it had a math mistake which is a quite common misconception for kids. I’ll post the link to the program and the original pic of the code here. Program: https://scratch.mit.edu/projects/76297504/#editor
The kids nested the math operations without really paying attention to the order of operations.
The Kim and Kanye Hot Tub Challenge:
- These kids did a great job modeling the math and even drew a boxy hot tub.
- I think Kanye would approve of this program. Slightly different math, accurate volume calculation (assuming input is inches).
Neville and Hermione Reptile Challenge:
- An interesting implementation that involves using events and messages to turn this into sort of animation. https://scratch.mit.edu/projects/76718870/#editor
- Cute program with little wizards in it, and slightly different math. https://scratch.mit.edu/projects/75931612/#editor
These were exemplars – there were some groups who were unsuccessful at the start, and as we’re in a standards-based system, the kids get as long as they want to show me they’ve mastered the use of variables. Many of them will get it as we work through the next few programming challenges. Overall I was so pleased and proud with their engagement, creativity, and attention to the precision in this task.
The problems I selected are very similar to word problems they’d be assigned in sixth-grade math class. Sixth grade is a big year for learning about variables and expressions, unit prices, area, and volume of rectangular prisms. The thinking is a little different when writing a computer program versus doing a word problem on paper, or with a calculator. The feedback is instantaneous, and you tend to test your program on several different inputs to see if you get reasonable answers. It’s easy to go back and revise your thinking if you have made a mistake, and more rewarding when you get the expression right. There are many correct ways to complete a task, some of which can involve quite a bit of creativity.