Skip to main content
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.

Available Extra Services

The JS Mini Hotel system supports the following extra services:

Breakfast

€10 per dayAdd daily breakfast service for your guests.

Parking

€15 per dayReserved parking space during the stay.

Late Check-out

€30 one-timeCheck out later than standard time.

Early Check-in

€20 one-timeCheck in earlier than standard time.

Adding Extras to a Reservation

Extras can be added to any existing reservation using the addExtras() function.
1

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.
2

Add extras to the reservation

Use the reservation ID to add extras:
main.js:63-69
const updatedReservation = addExtras(
  hotel,
  'RES-001',
  [
    { name: 'Breakfast', price: 10, quantity: 5 },
    { name: 'Parking', price: 15, quantity: 5 }
  ]
)
3

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:
main.js:154-166
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
}
  1. Validation: Checks if the reservation exists
  2. Find reservation: Locates the reservation in the hotel’s reservations array
  3. Add extras: Pushes the new extras to the reservation’s extras array
  4. Recalculate price: Updates the total price to include extras
  5. Return: Returns the updated reservation object

Price Recalculation

When extras are added, the total price is automatically recalculated.

How Extras Pricing Works

The system calculates the total extras price and adds it to the base room price:
utils.js:114-117
export function updateTotalPriceWithExtras(reservation, extras) {
  const extrasTotalPrice = getExtrasPrice(extras)
  return extrasTotalPrice + reservation.totalPrice
}
utils.js:122-127
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

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 }
]
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 }
]

Viewing Extras in Invoices

When a guest checks out, extras are itemized in the invoice:
utils.js:160-181
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

Build docs developers (and LLMs) love