Replacing Tuples With Arrays

The rota now rotates in JavaScript, and the header for the team channel is taking shape. The out-of-hours window, from six in the evening until eight the next morning, still exists only in the Python script. Whoever carries the pager needs those hours to be right.

In monday_rota.py, the team lead keeps that window as a tuple, a small fixed pair of numbers. JavaScript has no tuple type, and the natural port of that line runs without a complaint and prints the wrong hours. In this lesson, you’ll see why, and you’ll learn the two shapes a JavaScript developer uses instead.

Port the Out-of-Hours Window

The Python script stores the two hours together and reads them by position when it builds the header line:

Language: Python
ON_CALL_HOURS = (18, 8)
print(ON_CALL_HOURS)
print(f"Out of hours: {ON_CALL_HOURS[0]}:00 to {ON_CALL_HOURS[1]}:00")

Python shows the tuple and then the header line:

Language: Program Output
(18, 8)
Out of hours: 18:00 to 8:00

A line-by-line port keeps the parentheses, adds const, and swaps the f-string for a template literal. A template literal is JavaScript’s equivalent of an f-string, with backticks around the text and ${...} around each value. Before you run it, predict what the first console.log() prints:

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.