Nadia’s booking confirmations now run in JavaScript. The port prints the same twenty-five lines as the Python script, from the choir’s waived deposit to “Call before confirming: Maya Okafor, Ana Silva”.
The rules carried over, but you had to rethink each default and each match. You can now:
- Read
&&and||as operators that return one of their operands, asandandordo in Python. - Give an empty rooms array a default with a length check, since every array is truthy.
- Choose
||or??field by field:||for the blank phone,??for the choir’s zero deposit. - Fill in a request in place with
??=,||=, and&&=. - Port a
matchwith guards to anelse ifchain, and one with patterns to aswitchon the property that decides most cases, with the other checks as plain conditions. - Call a function from a lookup only when there’s one, with
?.(), and fall back with??.
Keep Asking One Question
For every default you port, ask: “Are 0, "", and false real answers here?” If they are, use ??. If none of them is, as with a blank phone, use ||.