Your port of Ruth’s script now posts the call for each morning, with the reason. One line is still missing: on a racing morning, the members’ page needs to say the race officer hasn’t confirmed yet, so nobody rigs a dinghy for a race that might still be called off. Ruth’s Python tests if decision == "racing" and not officer_confirmed:. The port needs JavaScript’s versions of and and not.
Wait for the Race Officer
JavaScript spells the logical operators as symbols. Here they are next to Python’s, with the strict inequality operator:
| Python | JavaScript |
|---|---|
a and b |
a && b |
a or b |
a \|\| b |
not a |
!a |
decision != "racing" |
decision !== "racing" |
With true and false on each side, && and || behave as and and or do, stopping at the first side that settles the answer. JavaScript and Python differ a little in which other values count as true. Asking About the Forecast and Warnings covers those differences. Here’s the officer line on the main morning, where both conditions hold:
const decision = "racing";
const officerConfirmed = false;
if (decision === "racing" && !officerConfirmed) {
console.log("Waiting for the race officer to confirm");
}
The port prints the same reminder as Ruth’s script:
Waiting for the race officer to confirm
Watch out for typing the Python words out of habit, and use &&, ||, and !: and in a condition stops the file with SyntaxError: Unexpected identifier 'and'. JavaScript reads not as a variable name, so if (not officerConfirmed) puts two names in a row, and the parser stops at the second with SyntaxError: Unexpected identifier 'officerConfirmed'.
Group and Negate Conditions
Precedence carries over: && binds tighter than ||, as and binds tighter than or, so a mixed condition groups as it would in Python. Ruth’s script cancels for a fog or thunder forecast and for gusts of 30 knots or more, so, leaving the wind aside, racing weather means a fair or showery forecast with gusts under 30 knots. On the gusty morning, the forecast is fair but gusts reach 31 knots. Before you run this check, decide which line says no:
const forecast = "fair";
const gustKnots = 31;
console.log(
forecast === "fair" || forecast === "showers" && gustKnots < 30,
);
console.log(
(forecast === "fair" || forecast === "showers") && gustKnots < 30,
);
The two lines disagree:
true
false
The first line reads as forecast === "fair" || (forecast === "showers" && gustKnots < 30), as Python would group it, so the fair forecast bypasses the gust check. The second line’s parentheses group the forecasts, which is what the rule means. When you mix && and ||, add the parentheses even where precedence already gives the grouping you want, so nobody reading the line has to work out which operator binds tighter.
Negating a whole comparison is where ! stops being a drop-in replacement for not. In Python, not in front of a comparison negates the whole comparison, but ! applies only to the value right after it. To ask whether the call is anything but racing, write decision !== "racing", or put the comparison in parentheses, !(decision === "racing"). On the calm morning, the call is postponed, and both spellings agree:
const decision = "postponed";
console.log(decision !== "racing");
console.log(!(decision === "racing"));
Each line says the call isn’t racing:
true
true
For a single comparison, a JavaScript developer writes !==, the strict partner of ===, rather than the loose !=, which converts types first. The !(...) form is there when you’d rather keep the comparison as written and negate its result.
Your port can now post the waiting-for-confirmation reminder on a racing morning, group a mixed weather check the way Ruth means it, and ask whether a call isn’t racing. Ruth’s chain still has two postponed branches, one for too little wind and one for too much.
In the next lesson, Checking a Wind Range With &&, you’ll see how Ruth’s script merges those two branches into a single wind range, 6 knots up to 25, and port that range test.