Locked learning resources

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

Unlock This Lesson

Locked learning resources

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

Unlock This Lesson

Porting the Booking Confirmations Script

Nadia’s JavaScript port reads the same five Millbrook booking requests, fills in missing hours and contact details, chooses the rooms, and prints each confirmation. It uses an ordered condition chain for staffing and a lookup of functions for caretaker notices.

Choose each default by what its field means. Check room-list length, use || so a blank phone falls back, and keep a real zero deposit with ??. Property assignments tidy each request without reassigning its binding.

Save the files in ~/booking-confirmations. Install a current Node version if needed, then check it with node --version. The examples were checked with Node 26. Create the folder with cd ~, mkdir booking-confirmations, and cd booking-confirmations; these commands work in macOS/Linux shells and Windows PowerShell.

In your editor, save this as package.json in that folder. It selects ECMAScript modules for the JavaScript file:

Language: JSON
{ "type": "module" }

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

00:00 Port Nadia’s booking confirmations to JavaScript, keeping this week’s printed report. The closing report is your next exercise. In your home folder, create booking-confirmations.

00:12 Save both scripts there. In your editor, create package.json with the content shown. It selects ECMAScript modules for the JavaScript file. Check your Node version before continuing.

00:27 Python’s defaults become fixed JavaScript bindings.

00:33 A const name can’t be reassigned. Keep the room rates in an object: those keys are written in the code. Put regular hirers in a Map because their names are data.

00:52 The choir’s zero deposit and stored phone carry over unchanged. Python’s triple-quoted export becomes a backtick string.

01:10 Its remaining JSON data stays unchanged. In JavaScript, JSON.parse() reads that text into request objects. Here are the same five bookings. Keep the form’s distinctions: Maya has no room ticked, Ana has blank number boxes, and Yoga has no notes field.

01:34 Port Python’s staffing match as the ordered condition chain from the guard lesson. The missing-count check comes first.

01:44 Then check over a hundred first.

01:49 Next check over sixty.

01:56 The remaining guests need one caretaker. Each return ends the call. Tom’s hundred and twenty guests get two caretakers. Ana’s missing count gets the call-the-hirer message.

02:12 Python’s notice patterns become the lookup of functions you used earlier. The music handler covers weddings and parties. The setup handler covers classes and meetings.

02:30 The lookup connects those known event kinds to their handlers. The setup handler checks for one room; otherwise it uses the plural notice. An optional call tries the selected handler.

02:46 For a missing entry, the fallback reads the kind directly, replacing Python’s capture pattern. Python’s report state sits before the request loop. A changing number uses let; the array keeps its binding while you add names.

03:03 Print the heading. Then visit each request with for...of. For each name, look up its regular-hirer settings. An unlisted hirer has no settings object.

03:20 Fill missing hours in place. Trim a nonblank note. Fill a blank phone from the regular’s settings or the message. These are the choices from the earlier lessons: blank strings need the truthy fallback; property updates leave the request’s const binding intact.

03:42 The choir now has its stored phone and trimmed note.

03:48 Keep the earlier length check for the room default. Maya’s unticked list selects the hall. Python sums the selected rates. In JavaScript, add each rate in a for...of loop.

04:03 For Tom’s wedding, hall and kitchen contribute thirty and twelve dollars an hour. Eight hours costs three hundred and thirty-six dollars.

04:14 Python’s settings lookup becomes an optional property read with the nullish fallback. As before, the choir’s zero is a real deposit, so it stays zero. Yoga keeps twenty-five dollars; an unlisted hirer gets the fifty-dollar default.

04:33 The deposit stays separate from the hourly hire charge. Now write each confirmation. The selected rooms join with ” and “. The two amounts get two decimal places at the print call.

04:50 This multiline interpolation keeps one output line. The source breaks sit inside expressions. Then print the phone. Print the staffing by calling its helper for this request.

05:05 Print the notice by calling its helper too. A nonblank note adds one more line. Tom’s fairy-lights note appears; an empty or absent note adds nothing. Keep the existing deposit accumulator.

05:23 Keep the call-list update at the end of each iteration. Each request now contributes its confirmation and any note. The closing report remains to be finished.

05:37 From the project folder, check the JavaScript file, then run it. The syntax check returns to the prompt without a message. Compare this run with Python’s report, line by line.

05:49 All twenty-three lines match its opening section. That checks this week’s output. The closing report is still outside this comparison. You have the JavaScript confirmations: the same requests, charges, staffing and notices as Python.

06:07 Keep each default tied to the field’s meaning. Next up: Finish the Booking Confirmations. Complete the closing report: deposits held, and the hirers to call before confirming.

Become a Member to join the conversation.