Extras are additional services that guests can add to their reservations, such as breakfast, parking, or special check-in/out times. This guide explains how to manage extras and how pricing is recalculated.
The JS Mini Hotel system supports the following extra services:
Breakfast €10 per day Add daily breakfast service for your guests.
Parking €15 per day Reserved parking space during the stay.
Late Check-out €30 one-time Check out later than standard time.
Early Check-in €20 one-time Check in earlier than standard time.
Extras can be added to any existing reservation using the addExtras() function.
Prepare the extras array
Each extra is an object with name, price, and quantity properties: const extras = [
{ name: 'Breakfast' , price: 10 , quantity: 5 },
{ name: 'Parking' , price: 15 , quantity: 5 }
]
Quantity typically matches the number of nights for daily services, or is set to 1 for one-time charges.
Add extras to the reservation
Use the reservation ID to add extras: const updatedReservation = addExtras (
hotel ,
'RES-001' ,
[
{ name: 'Breakfast' , price: 10 , quantity: 5 },
{ name: 'Parking' , price: 15 , quantity: 5 }
]
)
Verify the updated reservation
The function returns the updated reservation with extras and recalculated price: console . log ( 'Updated reservation:' , updatedReservation )
How the Function Works
Let’s examine the addExtras() function in detail:
function addExtras ( hotel , reservationId , extras ) {
if ( getReservationById ( hotel , reservationId ) === undefined ) {
console . log ( 'La reserva no existe, no se pueden añadir extras' )
return
}
const [ reservation ] = hotel . reservations . filter (
reservation => reservation . id === reservationId
)
reservation . extras . push ( ... extras )
reservation . totalPrice = updateTotalPriceWithExtras ( reservation , extras )
return reservation
}
Validation : Checks if the reservation exists
Find reservation : Locates the reservation in the hotel’s reservations array
Add extras : Pushes the new extras to the reservation’s extras array
Recalculate price : Updates the total price to include extras
Return : Returns the updated reservation object
Price Recalculation
When extras are added, the total price is automatically recalculated.
The system calculates the total extras price and adds it to the base room price:
export function updateTotalPriceWithExtras ( reservation , extras ) {
const extrasTotalPrice = getExtrasPrice ( extras )
return extrasTotalPrice + reservation . totalPrice
}
export function getExtrasPrice ( extras ) {
return extras . reduce (( acc , extra ) => {
acc += extra . price * extra . quantity
return acc
}, 0 )
}
The price calculation formula is: totalPrice = roomPrice + (extra.price × extra.quantity) for each extra.
Example Scenarios
Scenario 1: Adding Daily Services
A 5-night stay with breakfast and parking:
// Original reservation: 5 nights × €150/night = €750
const reservation = createReservation (
hotel ,
301 ,
{
name: 'Ana García' ,
email: '[email protected] ' ,
phone: '+34 612345678' ,
dni: '12345678A'
},
'2026-04-10' ,
'2026-04-15'
)
// Add breakfast and parking for all 5 nights
const withExtras = addExtras (
hotel ,
reservation . id ,
[
{ name: 'Breakfast' , price: 10 , quantity: 5 },
{ name: 'Parking' , price: 15 , quantity: 5 }
]
)
Scenario 2: One-Time Charges
Adding early check-in and late check-out:
// Add one-time charges
const withSpecialTimes = addExtras (
hotel ,
reservation . id ,
[
{ name: 'Early Check-in' , price: 20 , quantity: 1 },
{ name: 'Late Check-out' , price: 30 , quantity: 1 }
]
)
Scenario 3: Mixed Services
Combining daily and one-time services:
const fullExtras = addExtras (
hotel ,
reservation . id ,
[
{ name: 'Breakfast' , price: 10 , quantity: 5 },
{ name: 'Late Check-out' , price: 30 , quantity: 1 }
]
)
Error Handling
If you try to add extras to a non-existent reservation, the function will log an error and return undefined: addExtras ( hotel , 'RES-INVALID' , [ ... ])
// Console: "La reserva no existe, no se pueden añadir extras"
Best Practices
Calculate quantity based on nights
For daily services like breakfast or parking, set the quantity equal to the number of nights: const nights = reservation . nights
const extras = [
{ name: 'Breakfast' , price: 10 , quantity: nights },
{ name: 'Parking' , price: 15 , quantity: nights }
]
Validate reservation exists first
Always verify the reservation exists before attempting to add extras: const reservation = getReservationById ( hotel , reservationId )
if ( reservation ) {
addExtras ( hotel , reservationId , extras )
}
Maintain consistent pricing across your application by referencing a constants file: const EXTRA_PRICES = {
BREAKFAST: 10 ,
PARKING: 15 ,
LATE_CHECKOUT: 30 ,
EARLY_CHECKIN: 20
}
const extras = [
{ name: 'Breakfast' , price: EXTRA_PRICES . BREAKFAST , quantity: 5 }
]
When a guest checks out, extras are itemized in the invoice:
export function createInvoice ( hotel , reservation ) {
const room = getRoomByNumber ( hotel , reservation . roomNumber )
return {
reservationId: reservation . id ,
guest: reservation . guest ,
room: {
number: room . number ,
type: room . type
},
checkIn: reservation . checkIn ,
checkOut: reservation . checkOut ,
price: {
room: getTotalPrice ( room , reservation . checkIn , reservation . checkOut ),
extras: getExtrasPrice ( reservation . extras ),
total:
getTotalPrice ( room , reservation . checkIn , reservation . checkOut ) +
getExtrasPrice ( reservation . extras )
},
emisionDate: Temporal . Now . plainDateISO ()
}
}
The invoice separately shows room charges and extras charges for transparency.
Next Steps
Creating Reservations Learn how to create reservations from scratch
Generating Reports View revenue reports that include extras income