Learn
Booleans and Comparison Operators
Review

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 allow us to run a block of code if a condition is met.
  • The boolean data type is either the value TRUE or FALSE and is the foundation of programmatic decision making.
  • We use else to include a block of code to run when the condition is not met.
  • Comparison operators evaluate a relationship between two operands and return a boolean value.
    • The less than operator (<)
    • The less than or equal to operator (<=)
    • The greater than operator (>)
    • The greater than or equal to operator (>=)
    • The Identical operator (===)
    • The not identical operator (!==)
  • We can write conditionals with multiple if statements using the elseif construction.
  • Instead of using a series of if statements when we 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 switch statement.
  • The keyword break tells the computer to break out of the switch statement, without it, it will fall through the rest of the switch executing all the code until it reaches a break or the end of the statement.
  • A ternary operator (?:) is shorthand conditional operator. It takes three operands (a condition to check, an expression to return if the condition is TRUE, and an expression to return if the condition is FALSE).
  • Any value or expression inside a condition will be converted to TRUE or FALSE. We consider values that will convert to TRUE to be truthy and values that will convert to FALSE to be falsy.
  • We can get user input from the terminal with the readline() function.

That really is a lot… Take some time to practice and review! You’re doing great.

Instructions

We’ve provided you with a Harry Potter Sorting Hat Quiz program. Read through the code. It uses the skills you just learned! You can take the quiz yourself by running the program. You’ll need to enter php index.php in the terminal and respond when prompted. If you’re feeling ambitious, customize and/or expand the quiz!

Folder Icon

Take this course for free

Already have an account?