The AND gate on a web page
Answers are for parents and teachers.
1
What does the safer function return for Apply with only list1 = on (list2 is missing)?
on off unlit, because the missing value is replaced by off.
2
Write the if test for a page with three lists $x, $y and $z that lights the lamp only when all three are on.
if ($x == "on" && $y == "on" && $z == "on")
3
Find the slip: if ($choice1 = "on" && $choice2 == "on")
A single = stores a value instead of comparing; it should be ==.
4
The safer function gets list1 = on and list2 = “on ” with a space after on. What does it return, and why?
on off unlit. The text with a space is not exactly on, so it is replaced by off.
5
Say in one sentence why the page should not trust what the lists send.
A browser can send any text, so the page must accept only the values it expects.