# Prisoner’s Dilemma and Conditionals

The Prisoner’s Dilemma is a classic problem in philosophy, economics, computer science, and well – life. I love it because it’s really easy to simulate, even for a beginning programmer, and it’s a great starting point for discussions on how you can use a computer program as a simulation for real-life phenomena.

I found this video on YouTube to explain the Prisoner’s Dilemma, and although the cigarette ads are a little edgy for the middle school audience, I think it dives in just deep enough. I showed this to the kids first.

The assignment for the kids then was to model the Prisoner’s Dilemma in a computer program. At this point, we had learned about variables, boolean expressions, “if” and “if/else” statements, and random number generation – and that’s pretty much it, so these programs weren’t going to be anything fancy. Here were the requirements.

1) Use the random() function to choose randomly whether two prisoners (call them A and B) will cooperate or defect.

2) Write the prisoners’ choices to the screen.

3) Use “if” statements and boolean expressions. Write the score to the screen as follows:

If A and B both cooperate, they both get 1 year in prison.

If A cooperates and B defects, A gets 3 years in prison and B goes free.

If B cooperates and A defects, A goes free and B gets 3 years in prison.

If A and B both defect, they both get 2 years in prison.

I decided to make this a pair programming activity. The students know by now there are 4 types of activities in CS class. Pair programming where I pick the partners; pair programming where they pick the partners; solo activities; and non-programming larger group activites such as card sorts and analysis tasks and that kind of thing. For the Prisoner’s Dilemma, I got to assign the partners. I reminded everyone of the norms first, a la this video from Code.org (which we watched earlier in the year, it’s wonderful)

* Don’t grab the mouse or keyboard.

* Do talk about the work.

* Do switch roles often.

* Don’t be bossy.

* Do be respectful.

I put everyone’s name in a bucket. I drew one name, and then invited that person to draw a name for their partner. They’d decide who was going to be driver and navigator, and head to the computer to work on the Prisoner’s Dilemma program. I gave them the coin flipper we worked on last class as a starter. Some kids spun off the coin flipper, some looked at it for ideas, and others built a program from scratch.

They worked really, really well together. I thought it might have been a fluke in one class, but then when it happened in the next class, I knew it wasn’t a fluke. Some combination of the task, the setup, and the accountability made it pretty darn magical for a really beautiful class period.

They worked hard for about 10 minutes and then the questions started coming in fast and furious, but happily, kids didn’t tend to get stuck and stay stuck. Pair programming is great for harder tasks, and I use solo programming for the easier tasks.

Some of the programs I got were pretty awesome.

Kevin and Patrick’s program, below, draws little stick figures for the prisoners. What I like about it is that they figured out the basics of translation by adding 150 to all of the x-coordinates, but keeping everything else the same.

## Prisoners Dilema Kevin & Patrick

Made using: Khan Academy Computer Science.

In Maddie and Ragan’s program, they didn’t use the coin flipper’s random number generator, but used a random number generator from -11 to 11. We had an interesting discussion about whether the cut point between “defect” and “cooperate” should be at PrisonerA > 1 or PrisonerA > 0. They realized the probability of their prisoner cooperating was slightly less than the probability of defecting, but that the video indicated defecting was usually the better choice. I couldn’t argue.

## Maddie and Ragan Prisoner’s Dilemma

Made using: Khan Academy Computer Science.

In Cole and Austin’s program, the model didn’t quite meet the requirements I set at first. Prisoner A and Prisoner B don’t make independent choices. Rather, Cole programmed the whole thing to have a 1/5 chance of both prisoners cooperating, a 1/5 chance of one defecting and the other cooperating (almost – their random number generator doesn’t quite work like they think) and a 2/5 chance of both defecting. I challenged them on this because a) that’s not the model that was in the requirement, which was that Prisoner A and Prisoner B make independent choices, and b) Cole did all the work and didn’t leave anything for Austin. This turned into a little bit of a battle of wills and eventually I convinced Cole to spin off the existing program, let Austin drive, and create two different outcomes for prisoner A and prisoner B. But at the same time, I was pretty impressed that the kid reasoned through the situation and wrote the whole program before the video was even done playing.

## Prisoners Dilemma Cole and Austin

Made using: Khan Academy Computer Science. Justin and Ian were an interesting match, because Justin has been programming forever and pretty much knows all of this already. Ian is brand new to all of this and is still learning the basics of things like JavaScript syntax and how to use the coordinate plane. Justin wrote the program, and when he got done and called me over to check it, like 10 minutes after the activity started, I noticed it was pretty plain with a white background and plain text. I suggested they switch roles, let Ian drive and make the program fancier. Add color, add graphics, something to jazz it up so it’s a cooler simulation. So they did, and both kids did a marvelous job working together, and I think Ian came away understanding JavaScript a lot better than he did. Plus their prisoners are really cute.

## Spin-off of “Coin Flipper” ian r and justin b

Made using: Khan Academy Computer Science.

Then there’s Paul and Ethan’s program. They finished the basics in a hurry and then just giggled for the rest of class, and I walk over to check their work and they have this rainbowy creation. By far the fanciest Prisoner’s Dilemma simulator I got so far.

## Paul and Ethan Prisoner’s Dilemma

Made using: Khan Academy Computer Science.

As a closer to this lesson, I will include a tie-in to the Iterated Prisoner’s Dilemma. Playing PD one time is an interesting simulation, but of course in real life, you encounter people over and over again, and every interaction with someone can be its own round of PD.

According to the Wikipedia entry, in 1984, a computer science competition was held during which computer programs would play each other in a round-robin tournament, where in each round, they would play another program in “N” rounds of Prisoner’s Dilemma.

The winning strategy was called “Tit for Tat” and it was the simplest of all the programs entered, consisting of only four lines of code. It always opened by cooperating, and after that, it did to the opponent whatever the opponent chose in the previous round. That’s it. It scored more points than any other strategy.

When I was a kid, I enjoyed sci-fi/fantasy novels and one of my favorite authors was Piers Anthony. In his Xanth series, one of the books was Golem in the Gears. The final chapter of this book describes a multi-player Prisoner’s Dilemma situation in which two Golems and two Hags play 6 rounds each of PD and then compare their final scores in the end. The winning strategy was, of course, Tit for Tat, and I like to read this chapter of the book to the kids. They enjoy being read to, and it’s cool to see an obscure CS reference show up in a fantasy novel.

It would be interesting to have the kids write an iterated PD program. I am considering, as an extension, having the kids tweak their programs so they have what they think is the optimal probability of defecting vs. cooperating – and then tallying up the number of years in prison they get after “N” rounds against another prisoner. When we learn about loops, perhaps we can go back and modify the programs further and even splice two groups’ prisoners together to see how they do!

# Booleans and Conditionals

It takes a quarter, but by this time my semester-long CS class is really moving along well.

After the kids learned about variables and took their quiz, I decided tackle boolean expressions and “if” statements with them. During testing week, we had very short classes, so the introduction activities were very short and focused. This was OK for the time we had.

**Lesson 1:** Boolean Expression exploration. Students had used variables to store text and numbers, but the idea of the value true/false as information was new. I gave them this program and asked them to un-comment the commented lines, one at a time, and try to explain what those lines were doing.

We had a class discussion, especially focusing on these lines. The output is “a>b is false”. Why does it substitute “false” for the variable bool? The variable is assigned to the result of “a>b” which is false.

var a = 3;

var b = 4;

var bool = (a > b);

fill(112, 4, 112);

textSize(30);

text("a>b is " + bool, 50,100);

In their math classes, we usually don’t explore equations and inequalities in a situation where they may be false, so this understanding is new – that the > operator is a logic operator that has a result, and that result can be one of two values. For that matter, a math equation such as “3x + 2 = 8” is a true/false expression. In a computer program, you’d write it as “3 * x + 2 === 8” and it will evaluate to true for only one value of x. For any other value of x, you’ll get a value of false. Solving the classic two-step equation is identifying which sole value of x will make the expression evaluate to true.

In the rest of the program, we explore the difference between numeric data and text, and I have the students look at other operators used in boolean expressions: < and >, <= and >= (greater than or equal to / less than or equal to), ===, !== (not equal to), && (logical AND) and || (logical OR).

**Lesson 2**: Boolean worksheet and review of variables

I put the students into pairs and assigned them to this worksheet, done as a collaborative document.

The first page is on understanding variables – how assignment works and syntax. It gives them a chance to brush up on some middle school math standards as well!

The second page is on boolean expressions, and I included examples with properties of arithmetic – again, to review topics from math class and to encourage the kids to discuss and work out misconceptions about booleans.

We went over the answers and discussed the worksheet. These lessons were great for our brief instructional time on testing days. Kids found these activities engaging – tough but not too tough.

**Lesson 3**: Intro to “if” statements

I gave students this program and tasked them with changing the program so it showed a happy face instead of a sad face.

If Statement Starter: Happy Face

Many students figured this out really quickly, and they did this in various ways – either by changing the value of the variable “a”, by changing the boolean expression from “a>10” to “a<10” or something else true, or (in a couple of cases) changing the arc’s parameters so it made a smile instead of a frown!

At this point I did a bit of direct teaching about the “if” statement and its companion, “if/else”. If the boolean expression in the parentheses evaluates to true, the code inside the curly braces {} will be run. Otherwise, the code is skipped. In an if/else, there’s an alternate set of code in another set of curly braces, if the boolean expression is false.

I paired the students up and gave them the rest of the tasks in the program – change the program so it shows a happy face and uses the === operator, then uses the !== operator, then uses &&, and then uses ||.

An interesting thing came up during the discussion here! Some students wrote boolean expressions such as this one, which are nonsense boolean expressions but displayed the happy face anyway.

`var a = 5;`

var b = 10;

if(a && b > 0)

{

arc(200,210, 50,50,0,180);

}

The program would first evaluate b>0, which is TRUE, and then it would evaluate “5 AND true”, which is a nonsense boolean expression to us, but in JavaScript, 5 must evaluate to true because the happy face does display. But the expression doesn’t mean what the student thought it meant – it’s not the same as “a>0 && b>0”. But since the output was correct, the students were totally satisfied with their solution. This is a misconception I’ll really have to watch for. The conversations you have when a student’s mental model is wrong, but their output is still correct, are really fascinating and time-consuming and can either be really great or a big power struggle, or sometimes both.

I finished this set of lessons with a Kahoot! quiz, and the kids did reasonably well on it, so I was excited to move on to their Prisoner’s Dilemma programs for the following lesson – I’ll write about that in the next blog post.

Kahoot! on if statements, variables, and booleans

**Lesson 4**: The Coin Flipper

This activity was very teacher-directed and basically involved me modeling how to write a program that produced a random dice roll, and then a random coin flip – while the students followed along. It didn’t feel like a great lesson at the time, but it had some positives.

– Kids were on task and engaged pretty much the whole time.

– There’s something to just typing in a canned program. I don’t know what it is, but in my own experience, I got a lot out of doing this when I was a kid. My mom and I would find a program in a magazine, and I would just type it in right from the magazine pages. I’d find myself thinking about the code as I typed it in and understanding it far better than if the program had just appeared on my computer. It’s not the same level of cognitive demand as creating a program from scratch – but when you don’t have the tools to create a program from scratch, for some reason, typing in a canned program helps you develop the skills to use those tools.

So we did, and the kids saved their coin flipper programs to their libraries. I wanted them to understand the random() function and feel more confident with if statements, and this lesson actually seemed to work pretty well.

In the past, I hadn’t spent a lot of time working with the students on boolean expressions and operators – I was glad we did that this time around, so even though these lessons took the better part of a week, the kids were in a better position to really understand and use conditionals.

# Remixing, hacking, and Arduino

I participated in #csk8 chat on twitter the other day. I’m valuing these discussions and they’re really getting me thinking about teaching techniques in my middle school classes. This past Wednesday, one of the questions that came up was about the role of remixing in your CS classes.

One of my courses is an Arduino-based electronics class. It’s been a really interesting experiment in how remixing plays out in a classroom.

I started a set of lessons by giving kids a very direct, step-by-step lesson on how to create a simple circuit and make it blink.

Then, I introduced the piezo element (a really simple speaker/buzzer) and showed them a web page with an example program that would blink one light and play one note.

I grouped the kids such that every group had one person who knew how to read sheet music. The challenge I put before them was this: think about a show such as the World of Color at Disney. Disney engineers synchronize light, sound, water, and other media. The first step to doing this is a circuit with the piezo and a few LED’s. Pick a piece of music. Transcribe it into Arduino code. Make the lights blink while it plays.

I gave them two additional links:

SHEET MUSIC ONLINE

And then the kids got in their groups to plan and work. And it was kind of amazing, because they created the questions from there on out, and I helped them get resources, but they wanted to solve the problems on their own.

It was wild to see how the classroom transformed over the course of the project. Some students took my example program and copied and pasted the lines of code and changed parameters. They made inferences on how long a quarter note would last versus an eighth-note, how to use delays to make a rest, and so on. Then one group got the idea to do a Google search for “Arduino Piezo”, or something of that nature, and they found a project that used a piezo and some LED’s to play the Imperial March from Star Wars. They figured out by downloading the code and changing the pins of the piezo and LED, they could get someone else’s code to work. Another group heard the Death Star theme and decided they wanted to download a cool song too, so they search for, and found, an Arduino project that could play the Super Mario theme song. Kids excitedly went to each other’s desks. The ones that hacked the found programs exclaimed, “We’re done!”

I looked at their projects and gave them some praise for figuring out how to remix, re-wire, and hack another person’s code. I said: now you have to make it better! How are you going to make it better?

So the Death Star group looked in their Inventor’s Kit and found some other electronics. “What does this do?” They asked, holding up the LCD. I said “It’s a display. You can write text on it. There’s a book in the back of your kit that shows you how to wire it up. It’s a little complicated, but I think you have room on your breadboard if you want to test it out.”

So they used the book to wire up the LCD, then used Google again to find some code that would write text to the LCD, and they pasted that code into their Death Star program to make a music/light circuit that also displayed a message such as “I am your father”.

Then another student ran over to me, excited. “Did you see what they did? That’s so cool! Could we make a circuit that makes song lyrics scroll with the song? Could you show us how?”

Just like that, any preconceived goals I might have had for the class need to be re-adjusted, and the students’ learning takes a really different trajectory, and I have to rethink my role as a teacher.

This is what Arduino is all about, though. I’ve discovered it’s so much more than a hardware/software platform. It’s a community with its own social fabric, its own ways of sharing and communicating. It’s an interconnected world in which people invent new widgets, share them, and encourage other inventors to improve on the original. It’s exciting to plug students in to this community. This is what 21st century learning is all about!

These are just a few of the considerations that I think about as I watch the kids teach themselves Arduino.

1) It’s really intrinsically motivating. Remixing makes kids want to learn.

2) This is what “making” is all about. It’s not just about inventing, but participation in a community of other inventors. They’re plugging into that community. Eventually they’ll learn to give back to that community too.

3) It’s limited. They are going to quickly run into hardware and software structures that they can’t, and won’t, understand without some intervention and teaching.

4) At the same time, my teaching them isn’t as helpful if they haven’t already generated questions to answer. They have to need the teaching.

5) Some kids would be perfectly happy if they learned how to make the buzzer beep and the lights flash, and they went no further. They will need a push to find the just-right level of challenge to keep growing.

6) It is really challenging to find projects to hack that are developmentally appropriate for you. Some projects are complicated and fragile – hacking will break them without any understanding on your part. Some take so much cognitive effort and time, and you get so little out of them, that it’s not worth it. Some give you a huge reward for really very little effort and aren’t very extendable.

7) How would you assign a grade to a project in a class such as this? I haven’t figured out a good way to do this at all. I am reluctant to even give concrete requirements for a project, because I don’t want them to be limited by the requirements. I also don’t want to set the bar so low that they are satisfied with completing an easy project.

8) There are ethical concerns with remixing as well. Kids need to learn to give credit to original authors, and use found resources legally and thoughtfully.

My measures of success are vague and my challenge is just beginning. Remixing and hacking adds a lot of excitement to a class. It helps the kids become resourceful and independent, and it’s how inventors get things done in this interconnected world. In the 1980’s, I learned to code by remixing BASIC programs my mom and I found in magazines and on BBS services through our modem. I would have a hard time teaching in a programming environment that didn’t also let you browse and remix other programs, after seeing the benefits in class. It pushes you to see what’s possible – but it’s much, much different than traditional teaching and I’m still finding my way around this world.

# 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.

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.

# Variables in JavaScript: Tax and Discount program

This is a post about one of those lessons that crushes your notion of yourself as an effective teacher, and how you rebuild from that! I’ve been working with my 7th and 8th graders on the concept of variables for about a week, and they’ve been learning about percents and decimals for a couple of *years*. It’s harsh when you have that realization that they understood very little of either topic.

I was out of the classroom on Friday, so I had to leave a lesson with my Computer Science students that they could complete independently.

We’ve been learning about variables in JavaScript programming. I decided to leave them with this task:

Create a program that has variables for the cost of an item, the percent discount, and the percent tax rate. Use the program to calculate the new cost after the discount and tax. Display the new cost to the screen.

I put tons of resources on my Google Classroom page. They had a .pdf file with detail and some hints in it:

I also left them a video screencast of me going through the assignment, and giving them some hints.

Screencast part 1

Screencast part 2

I had really high hopes! My sub e-mailed me on Friday: “Kids are finishing 20 minutes into class! What do I have them do?” I thought: how amazing! They were so productive! I can’t wait to see the work they produced.

I wish I could have waited longer!

I logged onto my Google Classroom the next day and saw the awful truth: two students had actually completed the task correctly. TWO! About half of the remaining students had turned in a program at all. Of those, they were full of logical and mathematical errors. As I browsed through them, I decided the biggest issue was that the kids had little understanding how to calculate discount or tax. I used to teach 7th grade math. We spend a whole quarter on discount or tax. The knowledge (if it took at all) didn’t transfer. Another issue I had to tackle involved misunderstanding variables. It was harder to isolate, but this student example shows a little bit of both problems.

The student converted the tax of 5% into the decimal 0.5, which is incorrect. Tons of misunderstandings about discount and tax. Kids sometimes added the percents as dollar amounts… divided by 10 instead of 100 to convert to a decimal… divided by the percent instead of multiplying by the decimal… I saw just about every misconception with percents possible.

This student’s example shows some common misperceptions about variables too. It would have been more efficient to substitute “d / 100” instead of “0.10” in the code for the discount rate. The variable “k” was set by using a calculator to take the discount, instead of using a formula in the program. Another common problem was using assignment statements out of order – for example:

`total_cost = cost_w_discount + cost_w_discount * tax/100;`

`cost_w_discount = cost - cost * discount / 100;`

The cost_w_discount variable needs to be assigned first. In a less forgiving computer language or environment, the total_cost will be calculated from a cost_w_discount that hasn’t yet been calculated – so it could be garbage data.

This problems get to the heart of why text-based programming is so difficult for kids. There are an awful lot of ideas they need to have correct in order to program well.

It really did baffle me that students turned in their work looking like this. They should have been able to look at their output and tell the programs just weren’t doing the right math.

I decided to tackle the percent/tax calculation issue and then work with them on the programming concepts. I started by having them all go to Khan Academy to do the practice problems on discount, tax, and tip, using a calculator. I wanted them to pay careful attention to what math needed to be done to solve the problems.

After they did a few practice problems, we had a quick discussion to summarize their strategies. Most students came to a place where they turned the percent to a decimal, multiplied the original cost by that decimal to get the discount or tax, then added to or subtracted from the original cost. Some students understood where they went wrong in their program at this point, but I gave them another challenge.

I grouped the students and gave them a half-sheet with this prompt: The output is correct, if you use the values for the variables that I listed. Figure out what math I did. Be ready to explain it.

It turned out to be a good group activity, and the students discussed and used their calculators to do trial-and-error. It took them some time to remember that, for example, 3.5% is 0.035 – and that after you calculate the discounted amount, that’s what you tax – you don’t tax the original cost once you’ve subtracted the discount.

When we discussed the activity, the discussion went something like this.

Student: So you do 230 times 0.4 to calculate the discount.

Me: Why 0.4?

Student: Because you move the decimal over 2 places.

Me: So let’s say I’m a computer and I’m not smart enough to understand how to just move a decimal. Could I multiply or divide?

Student: Divide by…. um…

Student 2: 10.

Student 3: No, 100.

Student: Oh, yeah. 100. Divide by 100.

Me: Ok, so I calculate the discount this way. I’ll write “var dc = cost * discount / 100;”. That way it uses my variables. After you multipled 230 by 0.4, what did you do next?

Student: You take it away from the 230.

Me: So now I could say “cost = cost – dc;” That would subtract the discount and store the value back in that variable called “cost”. Now “cost” has changed. Did you deal with the tax next?

We went from there. Before I released the students to finish up their programs, I met with the two students who had completed the task correctly the first time. I gave them heaps of praise and asked if they would be TA’s for the rest of the class and help other students finish the program too. They were really excited to help, and as other students finished the task, they asked if they could TA as well.

Not everyone got done, but many more did, and I felt validated to hear students say “I didn’t really get this before. I do now.” This is really difficult work for some students to program in text for the first time. We still have issues with students using variables before they’ve been assigned and other misconceptions about coding. But it felt like progress and I was proud of how hard they worked to understand tax and discount. It’s not glamorous work, but it’s important. I plan to come back to it when we start on if/then statements, which I think we really need to start on and continue spiraling back to variables.

My spirit was crushed at first, but things finished OK. I had to remember, and still have to remember, that when a task completely falls apart, there’s more than one reason why. But we can make progress if we can isolate those reasons.

## Recent Comments