Intermediate Algorithm Scripting - Sum All Odd Fibonacci Numbers

Hello everyone, can anyone tell me what’s causing my code infinite loop?
And why my code is not working? To get what i mean more, click the challenge’s link

function sumFibs(Number) {
  let previousNumber = 0;
  let currentNumber = 1;
  currentNumber = currentNumber + previousNumber;
  let sum = 0;
if (currentNumber % 2 !== 0 && currentNumber <= Number) {
  sum += currentNumber;
  }
  return sum;
}

sumFibs(4);


// previous Number + current Number

// current number + sum

// current Number should be less or equal to the number + it should be odd

// odd current numbers which should be  less or equal to the number should be added together to find the sum

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15

Challenge Information:

Intermediate Algorithm Scripting - Sum All Odd Fibonacci Numbers

  • do you see currentNumber is being “different” at any iteration?

happy coding :slight_smile:

Yes, it will be changed, for examples,
0 + 1 = 1
1 + 1 = 2
1 + 2 = 3

Looking at the right side of the addition formaula, the value was changed, the old one was replaced by the result.

If it’s not correct, explain please

  • try using “console log” for that and see if that changes or not*
  • if it does changes, how many times does it change

happy coding :slight_smile:

1 Like