php · level 1 · unit 4 · lesson 4
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Build bigger questions with &&, || !.
&& means and. It links two conditions and gives true only when both sides are true. A cake needs flour and eggs: if either one is missing, there is no cake.
|| means . It gives true when at least one side is true, like a lie-in on Saturday or Sunday. ! means . It flips an answer, so !true is false.
A box holding true or false already counts as a condition. So if (!$has_eggs) reads like plain English: if not has eggs.
<?php
$has_flour = true;
$has_eggs = false;
if ($has_flour && $has_eggs) {
echo "Time to bake a cake!\n";
} elseif (!$has_eggs) {
echo "Off to the shop for eggs.\n";
} Write a full condition on each side, like $day === "Saturday" || $day === "Sunday".
guess first
Did you earn pudding? Make a guess.
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<?php
$ate_peas = true;
$ate_carrots = true;
if ($ate_peas || $ate_carrots) {
echo "Pudding time!\n";
} else {
echo "Veg first, please.\n";
}
your turn
Your turn. Get on the Twister.
The Twister has two rules: you must be 8 or older, and at least 120 cm tall. Choose an age and a height that get you on.
fix it
Since when are crisps healthy? Fix the check.
- Crisps are not an apple or a banana, yet it says healthy. Look at the right side of
||. "banana"on its own is not a question, and PHP counts it astrue. So theifalways wins.- Write the box name again:
$snack === "apple" || $snack === "banana", then press run.
nailed it
you can ask smarter questions now. :D
&&needs both sidestrue.||needs at least one.!flipstruetofalse, andfalsetotrue.- Write a full condition on each side of
&&or||.
new words in your collection
- and
- or
- not
This lesson isn’t saved. A free account remembers every lesson you finish.