Woah! We covered a lot in this lesson. Good work. Let’s review what we learned:
ifstatements allow us to run a block of code if a condition is met.
FALSEand is the foundation of programmatic decision making.
elseto include a block of code to run when the condition is not met.
ifstatements using the
ifstatements 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
breaktells 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
breakor the end of the statement.
?:) 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. We consider values that will convert to
TRUEto be truthy and values that will convert to
FALSEto be falsy.
That really is a lot… Take some time to practice and review! You’re doing great.
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!