Every Monday morning, the support lead runs monday_rota.py, and everyone learns who’s carrying the pager this week through the team channel. Everything that script does, from rotating the queue to sorting it for the HR wiki, starts from one Python list of six names. Before the JavaScript version can move anyone around, it needs that list.
In this lesson, you’ll build the rota as a JavaScript array, read both ends of it, and count its items. Most of your list habits carry over. The exception is what happens when you ask for a position that isn’t there. Start with the rota as it stood last Monday.
Write the Rota and Read Its Ends
The Python script keeps the rota in queue order, with last week’s person first. It reads the front of the queue with [0] and the back with [-1]:
rota = ["Marta", "Dev", "Sam", "Ines", "Kofi", "Bea"]
print(f"Last week: {rota[0]}")
print(f"Back of the queue: {rota[-1]}")
In the JavaScript port, the list becomes an array, JavaScript’s general-purpose list type. The literal uses the same square brackets and commas. With const, you can’t reassign the name rota to a different array, but the array itself can still change, which Monday’s rotation relies on. Template literals fill in for the f-strings:
const rota = ["Marta", "Dev", "Sam", "Ines", "Kofi", "Bea"];
console.log(`Last week: ${rota[0]}`);
console.log(`Back of the queue: ${rota.at(-1)}`);
Run it, and you get the same two lines as the Python script: