Chevron Left Icon
Booleans and Comparison Operators
Lesson 1 of 2
Chevron Right Icon
  1. 1
    Have you ever noticed that hyperlinks change color after you click them? If the link has been clicked, then the web browser renders it in purple, rather than blue. The programming concept that …
  2. 2
    We’re going to learn about a specific type of conditional called an if statement. An if statement follows this basic structure: if (/some condition/) { // Do something… } The parentheses ho…
  3. 3
    The condition, or expression, in an if statement can hold a boolean value—like TRUE or FALSE, a variable assigned to one of those values, or an expression that evaluates to TRUE or FALSE. Just …
  4. 4
    In this exercise we’re going to learn a few more comparison operators and see how we can use them to compare more than just number values. The identical operator (===) will return TRUE if the lef…
  5. 5
    So far, we’ve been writing conditionals that can only handle one condition. If that condition is met, we do one thing, otherwise we do something else. This only allows us one or two courses…
  6. 6
    We often want to compare a value, expression, or variable against many different possible values and run different code depending on which it matches. We can use a series of if/elseif statements wh…
  7. 7
    In the previous exercise, we taught you to use the keyword break after the block for each case. Without the keyword break, not only will the first matching case’s block run, but so will all the co…
  8. 8
    PHP offers a short-hand syntax to conditionally return a value. Before learning it, let’s consider some example code: $isClicked = FALSE; if ( $isClicked ) { $link_color = “purple”; } else { $…
  9. 9
    So far in our conditionals, we’ve been dealing with expressions that would evaluate to boolean values in any context. In practice, any value or expression in the condition will be converted
  10. 10
    The outcomes of programs we’ve been writing so far have been predetermined. Unless we manually change our code, it will produce the same results each time it’s run. But this isn’t very realistic. P…
  11. 11
    Woah! We covered a lot in this lesson. Good work. Let’s review what we learned: + Conditionals make it possible for programs to decide how to react to a wide variety of situations. + if statements …
  1. 1
    In the previous lesson, we explored the foundations of making decisions in programming: booleans and conditionals. In this lesson, we’ll deepen the complexity of our programs’ decision-making capab…
  2. 2
    Expressions that use logical operators evaluate to boolean values. The logical operator || takes two different boolean values or expressions as its operands and returns a single boolean value. …
  3. 3
    Often, we’ll encounter situations where we have more than one condition we need satisfied in order to take an action. The logical && operator returns TRUE only if both of its operands evaluat…
  4. 4
    The logical not operator (!) takes only a right operand. It reverses the boolean value of its operand. !TRUE; // Evaluates to: FALSE !FALSE; // Evaluates to: TRUE The not operator has very …
  5. 5
    The logical operator xor stands for exclusive or. It takes two different boolean values or expressions as its operands and returns a single boolean value. Unlike regular or which evaluates to TRU…
  6. 6
    An alternate syntax for logical || operator is the or operator, and an alternate syntax for logical && operator is the and operator. These operators have the advantage of making our code more human…
  7. 7
    Separation of concerns is the programming design principle of organizing code into distinct sections each handling a specific task. It enables us to quickly navigate our code and know where to look…
  8. 8
    Great job! You’ve learned the tools needed to craft programs with powerful decision making capabilities. Let’s review what we covered: + By nesting conditionals within one another, we can create br…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo