The route demo sent either an error or a destination to one callback. A workshop reservation has another constraint: requests must be positive whole numbers no greater than the available seats.
reserveSeats(requested, available, callback) should invoke its callback once, synchronously. On success, send { reserved: requested, remaining: available - requested }; on failure send an Error with the message Invalid seat request and a null result. Do not return a result in place of calling the callback.
A separate callback receives either an error or a value, once:
function checkBadge(id, callback) {
if (!id) return callback(new Error("Missing badge"), null);
callback(null, { badge: id });
}
checkBadge("B7", (error, result) => console.log(error, result.badge)); // null B7
reserveSeats: call the callback once with null error and a result containing reserved and remaining.new Error("Invalid seat request") and a null result, calling back once.Reserved 2 seats; 3 remain in a callback for 2 of 5 seats.Reject non-integers, zero, negative numbers, and requests over the available seats.
Invoke callback(error, null) on failure and callback(null, result) on success.