Oh thank You I got it … I used while loop instead however i wanted to know if i can solve it by for loop as well . As I think while loops can be converted into For loop.
function sumFibs(num) {
let fiboNums = [1,1];
let nextFibo = (fiboNums[fiboNums.length-2]+fiboNums[fiboNums.length-1]);
while ( nextFibo <= num) {
fiboNums.push(nextFibo);
nextFibo = (fiboNums[fiboNums.length-2]+fiboNums[fiboNums.length-1]);
}
console.log(num);
return fiboNums.filter(element => element%2 !==0).reduce((a,b) => a+b);
}
sumFibs(4);