Congratulations, you made it to the end of the course! Ruth’s race-day call now runs in JavaScript. On the main morning, race-day-call.js posts the same four lines as race_day_call.py, starting with “Saturday morning race: racing (good racing wind)” and “Course: harbour triangle”.
In this course, you learned how to:
- Write an
else ifchain with each branch in braces, and declarelet decision;andlet reason;above it - Give a
constvariable one of two values with the conditional operator, condition first, as instartHour < 12 ? "morning" : "afternoon", and drop the value into${} - Combine conditions with
&&,||, and!, as indecision === "racing" && !officerConfirmed, and negate a whole comparison with!==or!(...) - Check a range with two full comparisons,
6 <= windKnots && windKnots < 25 - Ask about one of several values with
["thunder", "fog"].includes(forecast)and about emptiness withwarnings.length > 0 - Match one value with
switch,break, stacked cases, anddefault - Look a value up with
COURSE_FOR[direction] ?? "short windward-leeward"when every case only picks a value
The order of Ruth’s rules carried over as written, since JavaScript also tries the conditions from the top and the first truthy one wins. The shape is what changed, because JavaScript doesn’t read indentation.
In Python, a name assigned in a branch is still there after the chain. In JavaScript, a variable declared with const inside a branch is available only there. So you declare decision and reason above the chain with let because each branch assigns them later. Type elif, and, or a conditional expression in Python’s order, and JavaScript stops the file with a SyntaxError that points at the line, which makes those the friendly mistakes.