← Trail· Lesson 10 of 10
See this lesson in JavaScript →
Final project: average calculator
Combine interfaces, literal types, typed functions, loops and decisions in a testable report card.

Build an average calculator that returns a report card, using pure functions. The contract becomes types:
interface Aluno { nome: string; notas: number[] }
type Situacao = 'aprovado' | 'recuperacao' | 'sem notas';
interface Boletim { nome: string; media: number | null; situacao: Situacao }
nome: copy the received name.media: sum ÷ count;nullwithout grades.situacao:'sem notas'ifmediaisnull;'aprovado'(passed) if ≥ 7; otherwise'recuperacao'(make-up).
Because media is number | null, TypeScript makes you handle null before comparing with 7. Because situacao is a literal union, a wrong string is rejected by the editor.
Try it
Change the grades and compare an empty list with a list containing zero.
Execute o código para ver a saída aqui.Exercise
Fill in both TODOs: the accumulator in calcularMedia and the decision in boletim. Check media === null first. Return a Boletim object. Feedback is in Portuguese.
Execute o código para ver a saída aqui.Edite o TypeScript e clique em Verificar.
You finished the trail
You turned problems into steps and typed every part: variables, unions, signatures, arrays and interfaces. Explain why an empty list, a zero grade and an average of exactly 7 are three different tests, and why types alone don’t replace them.