Is this code functional for sum of all odd fibonaci numbers

is this type of code ok?

function sumFibs(num) {
  var k = [1, 1];

  var p = 0;

  for (var i = 1; i <= num; i++) {
//make an array of Fibonaci number in k
    if (k[i] <= num){k.push(k[i] + k[i - 1])} ;
  }

  for (var i = 0; i < k.length; i++) {
//this loops thru the array (k) and if the item is odd and it's less than the given num, then it adds those numbers to get the sum.
    if (k[i] % 2 != 0 && k[i] <= num) {p = p + k[i]};
  }
  return p;
} 

sumFibs(75025);

Can you explain more of your code? I added some comments that is my explanation. Does this seem right? It seems correct to me. Are you gettin the right answer?

Good luck!

[edit: here’s a codepen - https://codepen.io/newman5/pen/JjYvNZQ ]

1 Like

Functional as working?