Sharing a Course Between Directions

With the members’ note fixed, the next part of Ruth’s script to port is the course picker. On a racing morning, a second match on the wind direction picks one of three courses. Two of its cases cover several directions, and case _: catches the rest:

Language: Python
direction = "NE"

match direction:
    case "N" | "NE":
        course = "harbour triangle"
    case "S" | "SW" | "W":
        course = "outer trapezoid"
    case _:
        course = "short windward-leeward"

A JavaScript case holds one value, so “either” takes another form. You’ll use fall-through to handle multiple values, then explore the lookup table JavaScript developers often write instead.

Stack Cases That Share a Course

Fall-through broke the members’ note, but here it helps. A label with no body runs straight into the next one, so directions that share a course become stacked cases, one label per line above a single body and break. Here’s Ruth’s course picker in JavaScript, for the main morning’s northeasterly:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.