Overview
This guide will walk you through the essential operations of JS Mini Hotel: creating a hotel, searching for available rooms, making a reservation, and checking in a guest.All code examples in this guide are taken directly from the actual implementation in
main.js.Prerequisites
Ensure you have:- Node.js installed (for ES6 module support)
- The JS Mini Hotel source files in your project
- Basic understanding of JavaScript and ES6 modules
Step-by-Step Guide
Create Your Hotel
Initialize your hotel with a name and room inventory:Expected Output:The hotel object is the central data structure that stores all hotel information.
Search for Available Rooms
Search for available rooms by date range and room type:Expected Output:
The function automatically filters out rooms that have conflicting reservations for the specified dates.
Add Extra Services (Optional)
Enhance the reservation with additional services:Expected Output:The total price is automatically recalculated when extras are added.
Check In the Guest
When the guest arrives, perform the check-in:Expected Output:What happens during check-in:
- Reservation status changes to
"checked-in" - Room status changes to
"occupied" - Check-in date is updated to today’s date
Check-in validates that the reservation exists, is confirmed, the check-in date is valid, and the room is available.
Complete Working Example
Here’s a complete example that ties everything together:Additional Operations
Check Out and Generate Invoice
- Change reservation status to
"checked-out" - Change room status to
"available" - Move reservation from
reservationstohistory - Return a detailed invoice
Cancel a Reservation
Generate Reports
Data Structures Reference
Hotel Object
Hotel Object
Room Object
Room Object
Reservation Object
Reservation Object
Next Steps
API Reference
Explore detailed documentation for all functions
Validation Rules
Learn about data validation and business rules
Managing Extras
Learn how to add extra services to reservations
Generating Reports
See how to generate occupancy and revenue reports