Fix a bug from a user report
- Skill
- Debugging with AI
- Time
- About 25 min
- Access
- Free
A small hotel uses the function below to decide whether a room can be booked. Support has forwarded two complaints:
“I tried to book Room 4 from the 12th to the 14th. The previous guest checks out on the 12th, but your site says the room isn’t available.”
“We cancelled a booking for Room 2 last week and the dates still show as taken.”
Bookings have a check-in date (start) and a check-out date (end). A guest checking out on the 12th and a new guest checking in on the 12th is normal hotel practice.
Do this
- Reproduce both problems with a small example before changing anything.
- Fix the function. Asking AI for the fix is fine; make sure you understand why it works.
- Check you didn’t break the normal case: overlapping bookings must still be rejected.
Submit
- The fixed function
- The root cause of each complaint, in a sentence or two each
- The test cases you ran (inputs and expected result)
availability.js
// availability.js// A booking looks like:// { roomId: 4, start: new Date('2026-12-10'), end: new Date('2026-12-12'), status: 'confirmed' | 'cancelled' }// start = check-in day, end = check-out day function isRoomAvailable(bookings, roomId, start, end) { const roomBookings = bookings.filter((b) => b.roomId === roomId); return roomBookings.every((b) => end < b.start || start > b.end);} module.exports = { isRoomAvailable };