# Using conditionals to understand rates

Computer programs start to become more interesting, interactive, and powerful when you can create the ability for them to make decisions. The conditional is a key concept! The ability to take one of two paths, to make a yes/no decision, is crucial to computing and algorithmic problem solving.

This lesson weaves rates in with conditionals. Relevant standards:

CSTA:L2:CPP:5 Implement problem solutions using a programming language, including: looping behavior, conditional statements, logic, expressions, variables, and functions.

CCSS.MATH.CONTENT.7.RP.A.1

Compute unit rates associated with ratios of fractions, including ratios of lengths, areas and other quantities measured in like or different units. *For example, if a person walks 1/2 mile in each 1/4 hour, compute the unit rate as the complex fraction ^{1/2}/_{1/4} miles per hour, equivalently 2 miles per hour*.

CCSS.MATH.CONTENT.7.RP.A.2.C

Represent proportional relationships by equations. *For example, if total cost t is proportional to the number n of items purchased at a constant price p, the relationship between the total cost and the number of items can be expressed as t = pn*.

I created a video to introduce the “if” statement to students. It’s a JavaScript dependent video. Other programming languages don’t use the same syntax for the “if” statement. The spelling, punctuation and grammar are all important when you work in a computer language.

The students’ task, as explained in the video, is to write a program that can help solve a common dilemma for me as a teacher. If two classes are racing to complete a game, and the two classes take different amounts of time but also have different amounts of students, how do I determine who won? Variables and expressions could be used to calculate the rates, and then a conditional statement would determine which class won.

The students did pairs programming for this activity. Each group opened the starter program which has the task in the comments.

After the groups worked on the task, we discussed some of the solutions. There were two main approaches:

Approach 1: Calculate the time per student. Lowest amount of time per student wins.

Approach 2: Calculate the number of students per second. The greater number of students per second wins.

Some common misconceptions were: adding the seconds and minutes together and treating that as the total time (instead of converting the minutes to seconds and then adding), misunderstanding the rate of time per student vs. students per second, and failing to use parentheses in their rate calculation, so the order of operations would make division happen before addition. (example: rate = min * 60 + sec / students; rather than rate = (min * 60 + sec) / students;)

The students did a great job overall, and the level of challenge seemed appropriate for most. I truly think the mathematics and the programming were at a very appropriate level of challenge, but as we get deeper into programming, students need to be more metacognitive, they need to ask questions of each other, they need to be resourceful in finding answers – and many students lack those skills.

We will learn about boolean expressions next with these ideas in mind!

# CS Variables and Expressions

To introduce students to variables and expressions, I used a flipped lesson on using formulas to calculate area, and then a pairs programming activity on divisibility.

Relevant CSTA and CCSS standards. I decided to have the kids work with the area of an ellipse because they enjoyed that connection with the area of a circle – it’s a challenging formula to write in a program, as well.

CSTA:L2:CPP:5 Implement problem solutions using a programming language, including: looping behavior, conditional statements, logic, expressions, variables, and functions.

CCSS.MATH.CONTENT.7.G.B.4

Know the formulas for the area and circumference of a circle and use them to solve problems; give an informal derivation of the relationship between the circumference and area of a circle.

CCSS.MATH.CONTENT.7.NS.A.2.C

Apply properties of operations as strategies to multiply and divide rational numbers.

To give the students vocabulary and build knowledge of syntax, I made a little video lesson for them to create shapes and calculate their area. This is their first introduction to assignment statements.

VIDEO LESSON: VARIABLES AND EXPRESSIONS

STARTER PROGRAM: Variables and Expressions

Their individual assignment was to finish the program, drawing an ellipse and calculating its area using a formula they found in a search engine. Many students didn’t process that the height and the width of the ellipse weren’t the same as the two radii, so they calculated pi * height * width to calculate area. I mentioned that I had remembered a circle had just about the same area as 3/4 of the area of the square enclosing it, so could it make sense that the ellipse had a greater area than a rectangle with the same width and height? The students partnered up to troubleshoot and write the expression correctly – some form of ea = 3.14159 * eh / 2 * ew / 2; We had a good discussion about whether or not parentheses were necessary in the formula.

Next, we did a quick whole-class lesson on floor division and modulo operators. Divisibility is a really important concept in mathematics and in computer science. In JavaScript, the two operations look like this.

` a = floor (b / c); // divides b / c. truncates to a whole number with floor().`

`a = floor (6/3); // a is assigned to 2`

`a = floor (10/3); // a is assigned to 3`

`a = floor (104 / 10); // a is assigned to 10`

`a = b % c; // divides b / c and assigns a to the remainder.`

`a = 6 % 3; // a is assigned to 0`

`a = 10 % 3; // a is assigned to 1`

`a = 104 % 10; // a is assigned to 4`

The next activity was a pairs-programming activity. I asked the students to find a partner. One would type, the other would look over their shoulder, read the prompt, make suggestions, and help troubleshoot. I set a timer so the roles would switch after 10 minutes. Students have a hard time switching roles! The one using the keyboard gets very comfortable in that position and the one not typing often is self-conscious about it. It will take some coaching for the kids to get more comfortable with pairs programming, but it will be worth it.

I gave the students a scenario. Let’s say I walk into a bank with 2778 pennies. I want to come out with the smallest number of coins and bills possible, so what will the bank give me and how did you come up with it?

We had a whole-class discussion about using division and modulo to come up with a twenty, a five, two ones, three quarters, and three leftover pennies. The students then got a starter program and started pairs programming. The starter program was about a fictional money system and making change.

This was a really challenging task and it would need quite a few catch-and-release times. I should have used more! During the summary, two different approaches to solving the money problem came out.

Solution 1: Convert to the biggest currency unit first, then divide up the leftovers. Some students related the problem to how we convert money. If I have 2778 pennies, I’ll look for how many hundreds, fifties, or twenties I can make first and work down. These kids had to calculate that there are 105 zinks in a zab and then work from there.

Solution 2: Convert to the second-smallest currency unit first, then make groups of the next-smallest, and so on. Each time the leftovers get assigned to the small currency units.

Great intro to variables and expressions – next we would tackle conditionals.

# Performance Assessment in CS

In my middle school CS class, I started a unit on text-based programming. I’m using the JavaScript language for this unit and working through Khan Academy CS, which I love! The CSTA standards help set some boundaries for the unit:

CSTA:L2:CPP:5 Implement problem solutions using a programming language, including: looping behavior, conditional statements, logic,

expressions, variables, and functions.

So interesting that the stuff we spend most of our time on in CS class is summarized in this one standard. Each item could be (well, usually is) expanded into a whole week’s worth of content or more!

I chose to start our JS unit with variables, expressions, and conditionals – the assessment was focused on these topics.

I decided to give the students a written quiz and also a performance task. I put both in a Google Doc, and I created an assignment in Google Classroom for the students to submit their performance task to me.

The written quiz has 3 questions, which are in the Google Doc. I had the students answer these on paper.

Question 1 asks students to determine the value of variables after several assignment statements.

Question 2 asks them to choose the best assignment statement for a given situation.

Question 3 asks the students to evaluate Boolean expressions.

I had a devil of a time writing the assessment, and at a first glance, I don’t think the students did very well. There are so many interwoven strands that it’s very, very hard to isolate individual skills you need to be a programmer. Kids need to know the syntax of the language, order of operations, mathematical modeling, the meaning of percents and decimals, and rules for operations on integers. They have to be detail-oriented enough to notice nested parentheses and they have to be good writers to explain their reasoning. If a student misses a question – how do I know which skill is deficient? Some students don’t understand that multiplying by a decimal makes a number smaller, or that multiplying by 0.25 doesn’t give you a 25% discount. Can I still assess whether they understand variables and expressions, or are those skills too entangled to separate them?

Tough call, and I’ll continue to search for ways to get that information.

I was prouder of the performance task. Here was the prompt. Students needed to create a new program on Khan Academy and work individually.

**In a sports tournament, the tigers will play the lions, and the eagles play the hawks. The winners of these two games will play in the championship. **

**These 4 variables represent the scores in the first game.**

**var tigers;**

**var lions;**

**var hawks;**

**var eagles;**

**Write a program that will write the names of the two teams playing in the championship. If there’s a tie in either game, you should write a message explaining that the game goes into overtime.**

**When you submit your assignment, you can attach a link to your Khan Academy program, or copy your program into a Google Doc and attach that here.**

**Everyone must do their own work.**

When I gave kids the task, the room got very, very quiet and there was 100% focus on creating their computer programs. I kept a clipboard with me. If students asked a question or if I gave them a hint, I made a tally on the clipboard. Some very quick students finished their programs early. Some took the entire class period to write a pretty simple program. Some kids took the entire class period to make programs that were really elaborate, with functions and multi-game simulations. The cool thing was, every kid’s program was different.

Here are some of my anchor quizzes.

A “4”: This program meets all of the requirements, and shows understanding of JavaScript syntax, “if” statements, and logical reasoning.

A “3”. Shows understanding of JavaScript syntax, “if” statements and logical reasoning. Made mistakes, but no major misconceptions. (student didn’t read entire prompt and did not address ties.)

A “2”. Student shows some misconceptions but is progressing. In this case, the student isn’t clear on the inequality symbols.

A “1”. This student is missing some major concepts.

I knew I would have some students who had been letting their friends carry the load of learning to program, who would be mighty lost during the assessment. I was right, but ultimately I want the kids to learn to code and my interest wasn’t in letting them fail. I made marks on my clipboard and pointed them to the documentation on Khan Academy – the sample code that used “if” statements and created text. I re-read the prompt with them and questioned them, and then cut the kids loose when the light bulb went on. I won’t give those students the grade for mastery, but some may have shown proficiency.

One of these students was really grateful for the opportunity to do the individual work. “I finally understand if statements!” That was the goal!

I’m bothered by the handful of students that turned in programs that were obviously not close to working. In programming, it’s very clear whether or not your product meets a standard. Why turn it in otherwise? I want the kids to demand more from themselves. On one hand, they were academically honest and didn’t turn in someone else’s work, but on the other, there were resources available to help them and they chose not to use the resources. I gave one student a pass to come in during ELO time and get help. He didn’t show up. What makes you just throw your hands up and quit?

Those students are high on my worry list, not just for computer programming – but for life. Here I go, fretting over teaching Grit.

To end on a positive note, most kids persevered, they created interesting and creative programs, and I loved grading the assignments using Google Classroom. I had the kids paste a link to their program in their assignment submission, and I’m in the process of working my way down the list and assigning grades. Easy!

## Recent Comments