Asking About the Forecast and Warnings

Your port can now tell whether the wind sits in the club’s range. Ruth’s script asks two questions before it looks at the wind, though: Is a warning in force, and is the forecast thunder or fog? Either condition cancels the race, however good the breeze.

Both checks lean on Python shortcuts. Ported line by line, each one runs without an error and answers a different question, so nothing tells you the call is wrong. In this lesson, you’ll ask JavaScript the questions Ruth intended.

Ask for One of and Not Empty

Ruth writes forecast in ("thunder", "fog") for the forecast and if warnings: for the coast guard’s warnings list, which is empty on most mornings. Here are both in JavaScript, plus the emptiness check for a dict, such as a settings record of the race officer’s overrides, empty when there are none:

Python JavaScript
forecast in ("thunder", "fog") ["thunder", "fog"].includes(forecast)
if warnings: if (warnings.length > 0)
if not settings: if (Object.keys(settings).length === 0)

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.