jeudi 25 février 2016

How do I add the result of 'for' loop in javascript?

I'm trying to get and print the sum of all values that fill the if condition, but so far no success.

Also, is there a way to delimit fib() with a max value, say, 999999, instead of delimiting it through numMax operations?

fib = function(numMax) {
    for (i = 0, j = 1, k = 0; k < numMax; i = j, j = x, k++) {
        x = i + j;
        if (x % 2 === 0) {
            console.log(x);
        }
    }
};
fib(32);

Aucun commentaire:

Enregistrer un commentaire