JavaScript program to print the first n terms of the Fibonacci sequence:

python tutorials and learn python

Created with Sketch.

JavaScript program to print the first n terms of the Fibonacci sequence:

let n = 10;
let first = 0;
let second = 1;

console.log(first);
console.log(second);

for (let i = 2; i < n; i++) {
  let next = first + second;
  console.log(next);
  first = second;
  second = next;
}

Leave a Reply

Your email address will not be published. Required fields are marked *