DEV Community

Discussion on: JavaScript: I have a problem to set the conditions of the beginnings of the loops.

Collapse
 
andybullet profile image
AndyBullet

Do not take it, is an error that I do in pastebin.

Collapse
 
guillaume profile image
Stawarz guillaume • Edited

Then I think most of the problem is the "return" you've put in each condition.
return put you out of your function.
The problem is you put two nested conditions, and in either of them the last instruction is return. So, before js parser can go further in the function, you give it the command to stop executing the function.
So it can never reach the last lines.
To find the answer, use the devtools of your browser. If you inspect your page and go to the debug section, you can put a mark on the js code and execute it step by step... this way you can see which part of your function is "read" by the js parser and which is not.