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.

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.

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!


Tags: , , , , ,

About dupriestmath

I'm a former software engineer who has taught middle school math and computer science for the past 6 years. I believe every kid has the right to be a thinker. I started this blog to save resources for integrating programming in the Common Core math classroom. I also use it to save my lessons and reflections from teaching budding computer scientists! Coding has transformed how I teach and think. You'll love what it does for you. You should try it.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: