0

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 2

2

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 the div whose id is chart) as an ordered HTML list (0-indexed for your debugging convenience) for the shuttle’s seats. Notice how it iterates over shuttle.seats, an array that’s initialized to be of size SEATS (which is defined atop js/service.js) in js/shuttle.js. Note that null represents an empty seat!

1
  • thanks so much. Accepted answer.
    – Kevin Wu
    Commented Sep 8, 2014 at 18:42
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .