Hello, here is the latest code that froze the fibonacci challenge page.
function sumFibs(num) {
var myArr = [];
var n;
for (i = 0; i < num; i++){
myArr.push(i);
}
return myArr;
}
sumFibs(4);
The issue is that every array within a loop, no matter how simple, freezes that page.
I have been attempting to do the challenge, but every program I tried froze the page. I would reset, and try again, with the same result.
Finally, I tried the code above, the loop and array stripped to the absolute essentials.
The page froze again.
I went on Gitterfor help, but nobody understood why it froze.
I searched github and found similar issues but those were either closed (sometimes without actually resolving the issue) or were not quite the same issue.
On the strength of this advice, I cleared my local browser.
"If your code crashes your browser, also try Clearing Your Browser's Local Storage."
Now I have lose all record of weeks of work I have done getting to this point.
I am using ChromeVersion 54.0.2840.99
on Windows 7 professional
on a Dell Notebook.

Tessa Murphy
_(email removed for privacy)_
@TheTessaMurphy Looking at your for loop, could you try making i a local variable with var or let, and see if it works?
This is not an issue with a challenge. I get the challenge. I can do the challenge on other platforms. This is an issue with the FCC page. The page freezes no matter what array I use. I posted the code to show that it freezes even with a very very simple loop and array. I believe that is fairly common practice when reporting bugs, to show the minimum required to cause an error -- in this case the page freezing. Manish-Giri, I've added the var to the i with no change in outcome. The page freezes.
Also, the help page advises people to clear their browsers. Doing that lost me all the progress I've made to this point. That, I would think, is also a bug.
I tried your code on the Sum All Fibonacci Numbers Challenge:
https://www.freecodecamp.com/challenges/sum-all-odd-fibonacci-numbers#?solution=%0A%2F%2F%20%2F%2F%20dp%20implementation%20of%20sumFibs%0A%2F%2F%20var%20sumFibs%20%3D%20function(n)%20%7B%0A%2F%2F%20%20%20%20%20if%20(%20n%20%3D%3D%3D%200%20)%20%7B%0A%2F%2F%20%20%20%20%20%20%20%20%20return%200%3B%0A%2F%2F%20%20%20%20%20%7D%0A%2F%2F%20%20%20%20%20let%20sumOdds%20%3D%200%3B%0A%2F%2F%20%20%20%20%20let%20prev%20%3D%200%2C%20curr%20%3D%201%3B%0A%2F%2F%20%20%20%20%20while%20(%20curr%20%3C%3D%20n%20)%20%7B%0A%2F%2F%20%20%20%20%20%20%20%20%20if%20(%20curr%20%25%202%20!%3D%3D%200%20)%20%7B%0A%2F%2F%20%20%20%20%20%20%20%20%20%20%20%20%20sumOdds%20%2B%3D%20curr%3B%0A%2F%2F%20%20%20%20%20%20%20%20%20%7D%0A%2F%2F%20%20%20%20%20%20%20%20%20let%20newCurr%20%3D%20prev%20%2B%20curr%3B%0A%2F%2F%20%20%20%20%20%20%20%20%20prev%20%3D%20curr%3B%0A%2F%2F%20%20%20%20%20%20%20%20%20curr%20%3D%20newCurr%3B%0A%2F%2F%20%20%20%20%20%7D%0A%2F%2F%20%20%20%20%20return%20sumOdds%3B%09%09%2F%2F%20build%20fib%20numbers%20%3C%3D%20num%0A%2F%2F%20%7D%3B%0A%09%0A%0A%2F%2F%20sumFibs(4)%3B%0A%0A%0A%0Afunction%20sumFibs(num)%20%7B%0Avar%20myArr%20%3D%20%5B%5D%3B%0Avar%20n%3B%0Afor%20(i%20%3D%200%3B%20i%20%3C%20num%3B%20i%2B%2B)%7B%0AmyArr.push(i)%3B%0A%7D%0Areturn%20myArr%3B%0A%7D%0A%0AsumFibs(4)%3B%0A
And sure enough, it froze the FCC webpage which is strange since running the code directly in the Chrome console returns myArr as expected.
Seems to not be a local issue.
Works in JS Bin too.
confirmed in staging
@TheTessaMurphy are you able to carry on with other challenges?
The issue seem to be myArr.push(i). In one test alone this will mutate myArr 40 million times.
Using myArr = myArr.concat([i]) keeps the browser alive during this operation
I have also experienced this issue
@raisedadead could this be some weird loop-protect thing?
Please try running the code with //noprotect at the top of your code in the editor. If it passes then it could be a loop protect issue, which we will have to look into.
The issue here is not with the time that takes the loop in the challenge code to finish (which is protected), but with tests that try to compare the result. For one test (sumFibs(4000000)) the code returns an array with 4,000,000 items (approximately 400MB of RAM). There's no protection against humongous arrays here so pretty much every challenge can be frozen just by making the code return large array.
Sorry I didn't see this and respond earlier. Succinctly, all the remedies
you've suggested are things I tried before I contacted you. The original
code that I sent you was after everything else had failed. I stripped it
down to the bare minimum to see if it still failed, and it did. That's when
I contacted you. The only clues I can offer are that it appeared to hang on
the return, in Chrome, which is the browser I usually use, but that I was
able to complete the assignment in another browser, firefox.
On Mon, Nov 28, 2016 at 11:39 PM, Mrugesh Mohapatra <
[email protected]> wrote:
Please try running the code with //noprotect at the top of your code in
the editor. If it passes then it could be a loop protect issue, which we
will have to look into.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/FreeCodeCamp/FreeCodeCamp/issues/11830#issuecomment-263498152,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AP8_rjooaweL03DyhU_dsNify7xDhJ8Oks5rC9bAgaJpZM4K9Aoh
.
Funny thing: since Firefox's JavaScript engine is less performant than Chrome's, pushing 4,000,000 items in a loop takes more than a second which triggers loopProtect to stop the execution. That's why there's no browser freezes in Firefox for this code.
@TheTessaMurphy fyi your current solution works in Chrome as well because it doesn't create humongous arrays any more.
You haven't actually lost any work for challenges that you've passed. All challenges that you pass and submit are stored in the database and are accessible from your profile page. Code that you see via the map is stored locally.
@ Brian, thanks, someone else pointed that out as well. I was in a panic
and hadn't thought things through clearly, after which I felt like an
idiot. But a greatly relieved idiot.
@Marzelin, my original code most certainly did cause the freeze. I saw
right away what I'd done, but by then the page was frozen. That was not the
mystery to me. It was the thirty or so screen freezes AFTER THAT that had
me worried. I had used no protect, I had shut down my computer and
restarted it. I had used run=disable to get back into the program and
reset the screen, again and again, and finally I had stripped my code down,
literally, to: for(i = 0; i < 4; i++){
var arr = i;
}
return i;
I don't remember if I actually added a var to the i or if arr was the
actual variable I used, but in essence that was the code. That is what I'm
trying to tell you. THAT code froze the screen in chrome. AFTER thirty or
so resets. I WAS able to complete the challenge in firefox after
addressing the errors I'd made. The stripped down code ran fine in Chrome
until I added the return. I would love to know what caused the continued
freezing on my pc and if maybe it would have worked just fine on another
computer, but mostly I'm just glad someone showed me a way to work around
the issue and move on. I am again working in Chrome. Only that challenge
was affected.
On Wed, Nov 30, 2016 at 1:19 AM, Brian notifications@github.com wrote:
You haven't actually lost any work for challenges that you've passed. All
challenges that you pass and submit are stored in the database and are
accessible from your profile page. Code that you see via the map is stored
locally.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/FreeCodeCamp/FreeCodeCamp/issues/11830#issuecomment-263822582,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AP8_rrWO-ggFYwnzEyVTJhrY61TIRd8sks5rDT-HgaJpZM4K9Aoh
.
@TheTessaMurphy, the issue you submitted is valid and confirmed by me and other people. Thank you for taking the time to make FreeCodeCamp a better learning platform.
FreeCodeCamp testing program doesn’t protect from every possible code that can freeze the browser. In this case it does not protect from creating really big arrays and performing operations on them. This line: new Array(1000000).join() is just one example of browser-freezing codes. It’s pretty hard to protect users from executing such statements since constructors for array literals cannot be overridden.
The FCC code works as expected, it’s just not capable to protect from such cases.
A browser freeze is caused by this test case:
"assert.deepEqual(sumFibs(4000000), 4613732, 'message: <code>sumFibs(4000000)</code> should return 4613732.');"
Side note: The test check if two objects are deep equal. Deep equality check is only needed when we check non-primitve objects. Numbers are primitives, so we don’t need deep equality checks here.
When the assertion fails, chai (assertion library used for testing) tries to be helpful and converts the objects into text form. Unfortunately, converting an array with 4,000,000 items into a string takes a long time.
As a workaround, the equality comparison can be done manually, and then checked for truthy result:
"assert.deepEqual(sumFibs(4000000) === 4613732, true, 'message: <code>sumFibs(4000000)<\/code> should return 4613732.');"
@marzelin It should still be tagged a bug because i use Chrome regularly and I've being stopped severally by JSBin's loop protect. And yeah, we'd still have a jank even if we change it to sumFibs(4000000) === 4613732, true,
@marhyorh
JSbin's loop protect is set to stop loop execution that takes longer than 100ms, while FCC's is set to 1s. So yes, JSbin has better loop protect ;)
If you have an idea for code that would prevent browser freezes caused by operations on large arrays, by all means go for it. :+1:
i think it's running an infinite loop thats why the browser freezes.
Also ran into this issue. Might have to approach the problem differently in order to avoid creating arrays that break the browser.
@Tikam02 Yeah. But we don't want the user's browser to freeze :sweat_smile:
This seems like valuable experience in how computers work. Perhaps some early explanations/warnings/instructions on how to prevent and deal with frozen browser tabs are more useful than protecting users from the experience.
I have debated even continuing this discussion but have found others in a
similar situation so feel it is necessary to make one last attempt at
communication. I did NOT file this bug because the browser froze on an
endless loop. Okay? This is very important and seems to be the primary
misunderstanding. I DO understand that browsers freeze on endless loops,
that that is expected behavior and that it was my error. I repeat, I DID
NOT file a bug because the browser froze on an endless loop.
I DID file a bug because after I had discovered my mistake, cleared the
mistake, reset my page AND the computer several times, the page continued
to freeze.
So, in summary, I DID NOT file a bug because the browser froze on an
endless loop. I DID file a bug because the page froze on an array that was
essentially: for (var i = 0; i <4; i++){ i++}; YES, I understand this
doesn't do anything but count. It was a test. To see if my page would
freeze on a basic loop, Which it did.
So, once again for good measure, I DID NOT file a bug because the page
froze on an endless loop. I DID file a bug because the page froze on a loop
that counted to 3.
And no, that is not how computers are supposed to work. That is a bug.
cheers.
On Sun, Dec 18, 2016 at 9:17 AM, Theron Cross notifications@github.com
wrote:
This seems like valuable experience in how computers work. Perhaps some
early explanations/warnings/instructions on how to prevent and deal with
frozen browser tabs are more useful than protecting users from the
experience.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/FreeCodeCamp/FreeCodeCamp/issues/11830#issuecomment-267833561,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AP8_ruLXjsT4gJcuhwOwpEni2uSt0q45ks5rJWrGgaJpZM4K9Aoh
.
Sorry @TheTessaMurphy , that comment wasn't directed at your bug, but some of the suggested 'fixes'. I'm trying to reproduce it now.
Thanks @theroncross !
No worries @theroncross https://github.com/theroncross. For the most part
I'm simply venting my frustration. After multiple attempts at rephrasing
and re-explaining, I still have no confidence that the central issue is
understood or acknowledged, never mind addressed or reproduced. If it helps
you understand the issue any, I can tell you I solved my immediate problem
by switching to another browser.
On Mon, Dec 19, 2016 at 10:04 AM, mrugesh mohapatra <
[email protected]> wrote:
Thanks @theroncross https://github.com/theroncross !
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/FreeCodeCamp/FreeCodeCamp/issues/11830#issuecomment-268033624,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AP8_rhkyPiThn9HZ36ZOYxnPrJs9OvDcks5rJscrgaJpZM4K9Aoh
.
Most helpful comment
Sorry @TheTessaMurphy , that comment wasn't directed at your bug, but some of the suggested 'fixes'. I'm trying to reproduce it now.