Intermediate Algorithm Scripting

Hello guys, I was practicing my Javascript after awhile not doing it, and bump into this code and kinda confuse how to interpret it

let firstPrev = 1;
let secondPrev = 0;

for (let i = 2; i <= count; i++) {
        let current = firstPrev + secondPrev;
        secondPrev = firstPrev;
        firstPrev = current;
    }

most confusing part is

        current = firstPrev + secondPrev;
        secondPrev = firstPrev;
        firstPrev = current;
 

im not sure what value is what. i remember back then there’s an explanation i read somewhere online, but i couldn’t remember it now. if anyone can explain how this work or got any link to explain it, please share it with me.

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

The count variable is not defined, so the code will throw an error.

hey there,

sorry this is just a section of the code, i didn’t show everything. in the full code the code runs fine.

im just wondering how does this work:

current = firstPrev + secondPrev;
        secondPrev = firstPrev;
        firstPrev = current;

It looks like a basic multiplier algorithm where the difference between the first and second will be multiplied by count-2.