Lab: language basics capstone
Bring together values, functions, control flow, arrays, objects, modules, and TypeScript in one session.
- Write functions that compose the core language features
- Transform and filter arrays of objects
- Use TypeScript type annotations on function signatures
Optional capstone lab. This session ties together everything from the module — values, functions, control flow, strings, arrays and objects, modules, and TypeScript basics. Three checkpoints, each building on the last.
Warm-up — run it first
A quick reminder of how much the array methods compose. Scan, run, confirm the output:
Checkpoint 1 — grade a score
Write letterGrade(score). Return 'A' for 90+, 'B' for 80–89, 'C' for
70–79, 'D' for 60–69, and 'F' for anything below.
Write letterGrade(score) returning 'A' for 90+, 'B' for 80–89, 'C' for 70–79, 'D' for 60–69, 'F' for below 60.
letterGrade(92) → 'A'letterGrade(74) → 'C'letterGrade(58) → 'F'Checkpoint 2 — summarise a roster
Given an array of student objects { name, score }, return a summary object
{ count, average, top } where top is the name of the student with the
highest score.
Write rosterSummary(students) where students is an array of { name, score }. Return { count, average, top } where count is the number of students, average is the mean score (rounded to 2 decimal places with toFixed, returned as a number), and top is the name of the highest scorer.
rosterSummary([{name:'Ana',score:90},{name:'Bo',score:80}]) → { count: 2, average: 85, top: 'Ana' }Checkpoint 3 — TypeScript annotation
The function below works but has no type information. Add TypeScript annotations
so the signature reads function formatCurrency(amount: number, currency: string): string.
Run to confirm the output is unchanged.
TypeScript's annotations live only in the type layer — the JS runtime ignores them, but your editor and the compiler will catch callers that pass the wrong type.
Done?
Three green checks means you can wire together the core language: control flow, array transforms, object shapes, and type annotations. That's the foundation everything else in JavaScript builds on.