TypeScript bootcamp · Lab 42

Fibonacci n

mediumWhile12 minLesson: While

Read the question, write TypeScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

1-indexed Fibonacci F1=F2=1.

Examples

Example 1
Input
6
Output
8
Hint
  1. two runners
Show correct code

Peek only after you have tried. You can still Check your own version.

const n: number = Number(readLine());
let a = 1, b = 1;
for (let i = 3; i <= n; i++) { const c = a + b; a = b; b = c; }
console.log(b);
main.tstsc · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.