I've been trying to solve the Fibonacci sequence and tried it with the following approach:
function fibbi(number) {
for (let number = 0; number < 10; number++) {
console.log(fibbi(number));
}if (number < 2) {
return number;
} else {
return fibbi(number - 1) + fibbi(number - 2);
}
}
fibbi(10);
Through that, I'm running into an infinite loop and I don't really understand why. Could someone walk me through this maybe? If I put the for loop outside of the function and call the function there, it will not run into an infinite loop.
Edit: Changed function name in else statement