Answers for "in javascript fibonacci sequence can besolved using for loop:"

4

fibonacci sequence in javascript using for loop

let fibonacci = [0, 1]; // set initial conditions

for (let i = 2; i < 10; ++i) {
    // add the two previous elements to get the current element
    fibonacci[i] = fibonacci[i - 2] + fibonacci[i - 1];
}

console.log(fibonacci); // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Posted by: Guest on May-31-2021

Code answers related to "in javascript fibonacci sequence can besolved using for loop:"

Code answers related to "Javascript"

Browse Popular Code Answers by Language