Porting the Race-Day Call Script
You’ve ported each part of Ruth’s race-day call on its own. In this project, you port most of her Python script into one file.
A port that runs can still make a different call, and a wrong one sends dinghies out in fog, so each line is written the JavaScript way, and for the main morning, the port prints Python’s first two lines. The members’ note, the racing-only course line and the waiting line are left for the exercise.
- The readings become constants, one
consteach, because nothing reassigns them. The names turn into camelCase, Python’sFalseisfalsein JavaScript, and the empty list of warnings becomes an empty array. - Every branch sets the decision and the reason, and the headline reads them later. In Python,
they outlive the branch, but a
constinside a JavaScript branch ends at its brace, so the port declares both withletabove the chain. - The first branch asks whether the warnings’ length is above zero,
warnings.length > 0. Every JavaScript array is truthy, even an empty one, unlike Python’s empty list, so the list alone would cancel every morning, for anundefinedwarning. - Each
elifbecomeselse if: anelsefollowed by anotherif, in its own braces. Typed out of habit,elifstops the file at the brace with aSyntaxError. - The forecast check asks the array whether it includes the forecast,
["thunder", "fog"].includes(forecast). Theinoperator looks at an array’s indexes, not its values, so it would send the fleet out on the fog morning. The gusts carry over unchanged. - The wind range joins two full comparisons with
&&. JavaScript has no chained comparisons, so Python’s form would race the calm morning’s 4 knots. - Anything else is postponed, and the reason comes from the conditional operator: the condition
first, then the two values. In Python’s order, the line stops at the
ifwith aSyntaxError. - On the calm morning, with 4 knots, gusts of 7 and the wind from the south, there are no warnings, the forecast is fair and the gusts are light, so the chain reaches the range, and 4 knots is under it. The conditional operator picks too little wind: postponed, as in Python.
- The course comes from a
switchover the direction. Directions that share a course stack their cases above one body and onebreak, anddefaulttakes the place ofcase _:. - In JavaScript,
|in a case is bitwise OR, a number operator:case "N" | "NE":compares with0, so it never matches. Without thebreaks, northeast would fall through to the short windward-leeward. Since each case only picks a name, many JavaScript developers use a lookup object; theswitchis equally correct, and lines up with Ruth’smatch. - The session is one conditional expression, so it’s a
constwith its final value. It could sit inside the template’s${}, as in an f-string. The headline’s f-string switches to a template literal: backticks for quotes, and a$before each brace. For now, the course line prints on every morning.
Here’s the port, race-day-call.js, with the members’ note, the racing test on the course line
and the waiting line still to come: