Final output
What you can create
Dunk reel at 42. Expired crush at 0. Like and Watch re-rank live.
Before you start
Not Fighter Arena
New folder. No Fighter, no attack(), no health. Type every .js file. If Feed uses instanceof, start that file over.
Full typed walkthrough: ACTIVITY-campus-feed.md
Type the parent
- 1
Create
js/content.js. - 2
Private
#likes. Publiclike()andgetLikes(). - 3
score()throws until a subclass writes it.
class Content {
#likes = 0;
constructor(creator, caption) {
this.creator = creator;
this.caption = caption;
}
like() { this.#likes += 1; }
getLikes() { return this.#likes; }
score() { throw new Error('implement score()'); }
}
globalThis.Content = Content;If main.js can write post.likes = 999, encapsulation is missing.
Photo, Story, Reel
- 1
Photo: score = likes.
- 2
Story: score = likes × 3, or 0 if hoursOld ≥ 24.
- 3
Reel: score = likes × 2 + watch seconds. Private #watchSeconds.
Photo → return this.getLikes()
Story → expired ? 0 : this.getLikes() * 3
Reel → return this.getLikes() * 2 + this.getWatchSeconds()Same method name. Three formulas. That is the hook.
Sort without asking the type
- 1
Feed HAS posts. It does not extend Content.
- 2
forYou() sorts by score() descending.
- 3
No instanceof. No if (kind === 'reel').
class Feed {
#posts = [];
add(post) { this.#posts.push(post); }
forYou() {
return this.#posts.slice().sort((a, b) => b.score() - a.score());
}
}If you add Poll later, Feed must stay untouched.
Campus posts on the For You page
- 1
Seed one Photo, one expired Story, one fresh Story, one Reel.
- 2
Like them. Watch the reel. Use your campus captions.
- 3
Draw cards from forYou() into #feed.
- 4
Close the laptop and write Reel.score() on paper.
The dunk reel beats the 30-hour crush story. Do the math: 42 vs 0.
Done checklist
Submit
Campus Feed repo only. Recite the formulas with the file closed.
| Deliverable | What to turn in |
|---|---|
| Repo | GitHub URL for campus-feed |
| Demo | Phone on screen — why rank 1 won |
| Defense | Write Reel.score() on paper |
Final output
Show this when you defend
Same four posts and formulas as the paper drill. Point at rank 1 and say why it won. Feed still only calls score().
Still on Warrior vs Witch? Finish the midterm roster then start a new folder.