Hello,
I had this problem with a previous test but I, somehow, fixed it, then I got stuck on this one.
All test results are correct yet it shows "X" marks on some test cases (depending on the test I use in the code itself!!).
As you can see, I had to use "pop" to remove the last element, I wonder what's the reason that makes it add an extra item to the array, hope someone can clarify on that.
Also I had to "not" use array.prototype.reduce, and I don't know why it didn't work at all for me, it returned null for a lot of cases, but that's a different matter.
Challenge Sum All Odd Fibonacci Numbers has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Maxthon/4.4.8.1000 Chrome/30.0.1599.101 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
var fibs = [1, 1];
var sum = 0;
function sumFibs(num) {
while (fibs[fibs.length - 1] <= num) {
fibs.push(fibs[fibs.length - 1] + fibs[fibs.length - 2]);
}
fibs.pop();
for (var i = 0; i < fibs.length; i++) {
if (fibs[i] % 2 !== 0) {
sum += fibs[i];
}
}
return sum;
}
sumFibs(1);
Thank you,
Muhammad A. Motawe
@MuhammadMotawe our tests are run one after each other so any global variables you declare are carried from one test execution to another. You have two global variables that are modified unintentionally by the tests. Place those variables (fibs and sum) within your function and your code will work. Happy coding!
that was the same solution to my previous issue, thanks a lot
thanks that helped me solve two of my previous challenges