How do we know how many seats are available in our shuttle? It is never specified anyway, instead the only thing that is given to us is an empty array. Does that mean we can specify the amount of seats?
2 Answers
The number of seats is defined in js/services.js
as explained in the pset:
Finally, take a look at the function called
chart
. That function renders a seating chart (in thediv
whoseid
ischart
) as an ordered HTML list (0-indexed for your debugging convenience) for the shuttle’s seats. Notice how it iterates overshuttle.seats
, an array that’s initialized to be of sizeSEATS
(which is defined atopjs/service.js
) injs/shuttle.js
. Note thatnull
represents an empty seat!
You'll probably need to create your own function that calculates and returns the number of available/occupied seats in the shuttle. Given that null
represents an empty seat, you can have something like this
create a variable named availableSeats and set it to 0
for each seat in the seats
{
if the current seat is equal to null
add 1 to availableSeats
}
return availableSeats
Alternatively, you can create a global variable that keeps track of the number of available/occupied seats in your shuttle. This variable should initially be set to the number of seats in your shuttle and decreases/increases as the passengers jump in/out of the shuttle.