function sumFibs(num) {
let prevNumber = 0;
let currNumber = 1;
let result = 0;
while (currNumber <= num) {
if (currNumber % 2 !== 0) {
result += currNumber;
}
currNumber += prevNumber;
prevNumber = currNumber - prevNumber;
}
return result;
}
// test here
sumFibs(4);

Could someone please explain the purpose of these last two lines of code to me?

The formula for Fibonacci numbers is f(n) = f(n - 1) + f(n - 2).

This means that f(n - 1) = f(n) - f(n - 2).

Let’s call f(n) something else, like currNumber and let’s call f(n - 1) something else, like prevNumber. These two equations are what this solution is using.