Operators and the if statement
Answers are for parents and teachers.
1
Trace $x: $x = 9; $x -= 4; $x *= 3; $x %= 7; $x++;
9, 5, 15, 1, 2. The final value is 2.
2
Complete the truth table for X ∨ Y when X is false and Y is true; then for X ∧ Y.
X ∨ Y is true; X ∧ Y is false.
3
A shop gives a discount to members with 20 points or more. Write the condition, then say whether a member with exactly 20 points gets it.
$points >= 20; yes, 20 is included.
4
What does this print? $age = 15; if ($age >= 18) { echo "adult"; } elseif ($age >= 13) { echo "teen"; } else { echo "child"; }
teen.
5
Find the two syntax mistakes: $y = ($x = = 1) ? "A" : "B"; and $count–;
A space inside ==, and a long dash instead of two minus signs in $count--;.