I need help with the fibonacci

I need help with the fibonacci
0.0 0

#1
function sumFibs(num) {
  var l = [0,1];
  var ans = 1;
  var curr = 0;
  var n = 0;
  
  for(var i = 1; i < num; i++){
    n = l[curr] + l[i];
    curr++;
  if(n < num){
    if(n%2 !== 0){
      ans+=n;
      l.push(n);
    }  
    if(n%2 === 0){
      l.push(n);
    }
  }
  }
  return ans;
}

sumFibs(4);

its iterative to many times. How can I stop this?


#2

i solved it lol

function sumFibs(num) {
  var l = [0,1];
  var ans = 1;
  var curr = 0;
  var n = 0;
  
  for(var i = 1; i < num; i++){
    n = l[curr] + l[i];
    curr++;
  if(n <= num){
    if(n%2 !== 0){
      ans+=n;
      l.push(n);
    }  
    if(n%2 === 0){
      l.push(n);
    }
  }
  }
  return ans;
}

sumFibs(4);