Final output
What Day 2 looks like
Fare · Alight · Start all. Habal fill → illegal → alight → sakay again.
Before you start
Track B only
Same repo. No new folder. If Start + Sakay are not working yet, finish Day 1 first.
Full typed walkthrough: ACTIVITY-ride-start-private-fare.md
Private label + capacity
- 1
Edit
js/ride.js: add#labeland#maxPax. - 2
Constructor:
constructor(label, maxPax). Getter for label.maxPassengers()returns#maxPax. - 3
Subclasses:
super('Habal-habal', 3)— delete hard-coded max overrides.
#label;
#maxPax;
constructor(label, maxPax) { … }
maxPassengers() { return this.#maxPax; }ride.#maxPax = 99 → SyntaxError. Private means outsiders cannot touch it.
Private fare rate + fareTag()
- 1
Extend constructor:
constructor(label, maxPax, fareRate)with private#fareRate. - 2
Parent
fare(n)does the math. Subclasses only overridefareTag()(funny label). - 3
Rates: Jeep ₱13 · Trike ₱20 · Habal ₱25 via
super(…, rate).
constructor() {
super('Habal-habal', 3, 25);
}
fareTag() { return 'Special trip'; }Same fare() path. Different tags and rates. Polymorphism + encapsulation.
Garage.fareSelected + Fare button
- 1
Add
fareSelected(count)— only callsthis.#selected.fare(count). - 2
HTML: Fare button. CSS:
.fare-btn. Wire inmain.js. - 3
No instanceof.
fareSelected(count) {
return this.#selected.fare(count);
}Habal Fare(2) → ₱50. Jeep Fare(2) → ₱26. Same button.
Private #boarded + seatsLeft
- 1
Add
#boarded = 0,boarded(),seatsLeft(). - 2
Rewrite
sakay(n)to checkseatsLeft(), then#boarded += n. - 3
Add
alight(n)— cannot alight more than aboard.
if (n > this.seatsLeft()) {
return 'Pffft… illegal recruitment. '
+ this.seatsLeft() + ' seat(s) left…';
}
this.#boarded += n;
return this.boardOk(n) + ' · aboard ' + this.#boarded + '/' + this.#maxPax;Habal sakay(2) → sakay(2) illegal (1 left) → alight(1) → sakay(1) ok.
Garage alightSelected + startAll
- 1
Add
alightSelected(count)andstatusSelected(). - 2
Add
startAll()— map every ride'sstart()into one string. - 3
Still zero instanceof. This is the polymorphism loop.
startAll() {
return this.#rides
.map((ride) => ride.label + ': ' + ride.start())
.join(' · ');
}startAll() shouts Jeep + Habal + … in one line without asking types.
Wire Alight + Start all + list aboard
- 1
HTML: Alight button + Start all button. Style both.
- 2
List rows show
aboard 2/3. Refresh list after sakay/alight. - 3
Hint uses
garage.statusSelected().
alightBtn.addEventListener('click', () => {
const line = garage.alightSelected(paxInput.value);
showLine(line, garage.selected().kind() + '.alight(…)');
hint.textContent = garage.statusSelected();
renderList();
});
startAllBtn.addEventListener('click', () => {
showLine(garage.startAll(), 'garage.startAll()');
});Compare with the final output demo when stuck.
Done checklist
Submit
Same Ride Start repo — new commits. Paper answers for the shared drill.
| Deliverable | What to turn in |
|---|---|
| Repo | Same GitHub URL — commits for private, fare, boarded, startAll |
| Demo | Fare(2) Habal≠Jeep · fill habal then illegal sakay · alight · Start all |
| Defense | Why #boarded is private; why startAll needs no instanceof |
Still building Day 1? Open Ride Start core