Not well structured while loop - you’re immediately re-assign accumulator which makes loop condition almost pointless and forces you to check if it’s less than n again later - think if you can avoid this
Naming is a bit confusing, normally you would expect something called accumulator to accumulate sum
If, let’s say, you start with the following variables:
let [prev, next] = [0, 1];
let sum = 0;
this will make this function way cleaner in my opinion
Thanks a lot my bro for this invaluable feedback . I have made some modifications to my code and now it looks concise and clear. Please check it.
function fiboEvenSum(n) {
let [prev, next] = [0, 1], value = 0, total = 0;
while (next <n){
if (value % 2 === 0){
total += value;
}
value = prev + next;
prev = next;
next = value;
}
return total;
}
console.log(fiboEvenSum(60));```