Booleans and Conditionals – Lessons and Reflections

Ask a CS teacher about a main goal of their course, and a lot of us say we want kids to be able to plan and write a program independently. And that it’s a discouraging but real part of the job that many don’t.

I really take that mission seriously, and as a result I move really slowly through topics.  I’ve mentioned before that I take weeks just to teach variables. This post contains a sampling of some of my lessons on booleans and conditionals.

Lesson 1: Structure and purpose of boolean expressions and conditionals.
Objectives: Identify the boolean data type and describe the rules that govern booleans, including logic operators.
Identify and describe the structure of the “if” statement.

We started by analyzing code samples and then modifying them – first with a partner, then whole-class. I created one that introduces the boolean data type and another that uses a variable and an “if” statement to simulate a coin toss.

CODE SAMPLES FOR ANALYZING

That said, I’d love to have a protocol or a structure or organizer for code-analysis problems. If you have one you like, I hope you share it!

Lesson 2: Prisoner’s Dilemma

Objectives: Use boolean expressions and conditionals to create a program that models a situation.
I love this lesson and have blogged about it before here.  Kids used Processing standalone instead of Khan Academy this year, but the task was pretty much the same. This is a pair programming activity. The “release of responsibility” is very gradual.

Lesson 3: Button Clicks

Objectives: Describe an area of the screen with boolean expressions.
This lesson has a very clear mapping to Common Core math standards. In Algebra, students are introduced to solving inequalities and also systems of equations. Later in high school math, students move to solving systems of inequalities.  When you create a clickable button, you’re describing the coordinates that are included in the ‘button’ as a boolean expression, which maps nicely to a system of inequalities.

Here’s the starter program.

http://www.openprocessing.org/sketch/231512

http://www.openprocessing.org/sketch/231512/embed/?width=500&height=500&border=true

We start with the mouseClicked() function incomplete and discuss as a class how to finish it. We look at the coordinates, height, and width of the rectangle and consider some x,y coordinates that are inside the rectangle… and some that are outside. Then we try to come up with a general sentence for which coordinates are always inside the rectangle. The x-coordinate must be between 150 and 350. The y-coordinate also must be between 200 and 300. If all of the conditions are true, you have clicked inside the box. If even one is false, you have not clicked in the box.

Then I give the kids a challenge:  create two buttons, one in the upper-left quadrant, one in the lower-right. Make something “happy” happen when you click one of the buttons, and make the other one produce something “sad”. They made some clever creations and had fun with it.

Alex P’s “Two Button Task”

Lesson 4: If/then quiz

The “quiz” task is individual, so at this point the students no longer get to work with a partner and must create a program solo. I make this task easier than the pair programming tasks, with the goal of every kid writing their own program from beginning to end.

This task is pretty simple but ended up requiring some good thinking from the kids.


 

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.
int tigers;
int lions;
int hawks;
int 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.


Although it’s a quiz, if a student raises his or her hand, I help. I help by asking questions – something I studied hard at when I was a math teacher.  The goal of the questions is to determine just how much help they need and give only that. Ask:

  • Read the problem to me again. What do you understand so far?
  • Where did you get stuck?
  • Under what condition would you write “tigers win”?
  • What causes a tie?
  • Tell me your best idea so far?
  • Can you translate that into code the computer can understand?

By the time the quiz comes around, there are definitely still misconceptions all over the place and it takes time to work through them all. Some of the ones I run into:

  • Writing a boolean expression in words, such as “tigers less than lions”
  • Mixing up > and < signs
  • Confusing equality (==) with assignment (=) operators
  • Not closing text strings with quotes (shows more than just a syntax problem – they’re not seeing the text string as a single entity)
  • Confusing the variable name with text (e.g. lions vs. “lions”)
  • Not yet understanding the purpose of variables as an “input” to the problem that can change. for example, a student may write this code, which renders their variables pointless:
    lions = 14;
    tigers = 10;
    if(14 > 10)
    { text(“lions win!”,50,50);}
  • These are misconceptions where the students are, at some level, not getting the point of a CS concept. Mistakes abound also such as syntax errors. These are different kinds of problems and have to be treated as such… I have a couple of students who generally get the CS concepts but they make tons of syntax errors. I have no problem looking through their program for the semicolons and spelling errors and just fixing them quickly. A kid who is not getting a concept, though, needs more questioning and more work.

When I taught math, one of our big ideas in 7th/8th grade was the “two-step linear equation” and how to solve it. I learned over time there are no shortcuts to mastering this concept. Sometimes there were many kids in the room who just needed me to sit with them, and one on one, watch them solve the problems in great detail and give them feedback on that work. These early programming tasks require the same attention from me. Many students just need me to sit with them, one on one, and talk with them as they program and solve. It’s a time-consuming task – in the moment, you think to yourself this lesson clearly bombed – the kids can’t program independently and I’m just doing damage control. But I have noticed as I have taught this age group more, that the early work pays off by the end of the semester. By the time kids are done with the class, you give them a simple task with conditionals and they just pound it out with barely any effort. Even the struggling learners do learn to program independently. It just takes more time and practice and attention for some kids than others.

 

Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: