Just recently delved into the world of Js and encountered an issue that has me stumped. Despite exhaustive searching, I haven't been able to find a similar solution. Any assistance would be greatly appreciated.
var i = 0;
var j = 1;
var k = 0;
function calculateFibonacci(n) {
if (n === 1) {
console.log([0]);
} else if (n === 2) {
console.log([0, 1]);
} else {
while (k <= n) {
var sequence = [0, 1];
var length = sequence.length;
sequence.push(sequence[length - 2] + sequence[length - 1]);
k++;
}
}
return sequence;
}
calculateFibonacci(4);
console.log(sequence);