1
I have these two construction functions that should create three passengers and a wagon and I need to create a method that when a passenger is added to the wagon he adds his name to the Passenger array of the wagon and decreases the capacity by 1.
I’ve already made the method decrease the capacity, but I can’t get the names of the passengers. I could take the names of the three walkers created and push the array, but I would have a way to make any name created with that constructor add to the array.
function Traveler(name) {
this.name = name;
this.food = 1;
this.isHealthy = true;
}
function Wagon(capacity) {
this.capacity = capacity;
this.passengers = [];
}