TarefaQuick recap. Inside <script type='module'>: write function* range(n) yielding 1..n. Sum them with reduce inside a try block: const total = [...range(4)].reduce((a,b) => a+b, 0). console.log(total) — should print 10. Also catch any error (none expected) and log 'no error'.
Recap: Iterators, fetch, errors (C4-C6)
50 XP5 min
Teoria
Quick recap — Modules C4-C6
Async patterns and iteration. The 4 pieces that show up in every real codebase:
- `for...of` — iterate any iterable: arrays, Maps, Sets, generators, NodeLists.
- **
function*generator** — yield values lazily.for-ofconsumes them. - `try/catch` around `await` — the rejection path. Without it, unhandled rejections bring down Node and noise up the browser.
- `Array.prototype.reduce` — sum, group, build any aggregate in one pass.
If any feels random, redo C5-03 / C6-04 / C4-07 / C5-09 then come back.
🔒
Regista-te para começar a programar
A teoria está aberta a todos. O editor, a pré-visualização e o check desbloqueiam-se com um teste gratuito de 7 dias — cartão obrigatório, cancelável a qualquer momento.
Registar — teste grátis →As primeiras 10 lições de cada trilha são grátis. Sem cartão necessário.