While loop's


7.5 "Practice makes perfect"

So I put this code in a html file and I used breakpoint so I can see how it behaves, the problem is that it dosen't print anything in the console and after it checks the loop condition, it leaves the function and there for nothing is beeing printed out in the console

Replace this line with your code. 
var loop = function(value){
		//Your code goes here!
		console.log("I am looping");
		loop = false;



How can you tell that the code is executed at all if you're not seeing any printing?
Maybe it's just not running.


Oh. Breakpoints. Debugger.

Your code is a little.. wonky, but it does print.
Why it does not print in your test can't be determined from your code since your code does print. You'd have to explain how to reproduce what you did, exactly as you did it!

Perhaps it did print, without you noticing. Perhaps you were looking in the wrong place.

Or perhaps the javascript didn't run after all.


You say that you cannot see something being printed when you run this in an html file. Are you aware of the fact that console.log prints to the console and not to the website?

Also think of a better condition than the name of your function. Currently a second run of the function is impossible because you overwrite your function with false in the first run, which makes it pretty pointless as a function, doesn't it?


I was looking in the console and I don't even need to because when you use breakpoints you can see how the program works and the exact steps it takes. And it just dosen't run anything inside the while loop exept checking the condition. It jumps console.log and loop = false. I expected that the program will console.log("") and than after the loop would take the value false, would go back and check if the condition is true and skip the console.log. But my function take the value of the loop("true"), it checks it and then leaves the function jumping at "};".
The console I am watching is the one near the source tab.
And I know that if I use this code on the exercise on codecademy it prints out in the console but I don't know why:
If you have a better way to do this code please wright it down so I could see the difference
I know how to make a html page and link a js file so I could see how to program goes.


If you want examples of how to run javascript code on a html page, then I suggest searching for it, I'd be saying the same thing as you would find there, that information is already available to you.

Your code is as mentioned very dodgy, but even though it might not do exactly what you think, it does print that string, once. If you're not seeing that print then it sounds like there's something not quite right about your observations.

It's usually a good idea to start out with a minimal example when testing something, so that you can minimize the number of things that can go wrong. For example you could instead use a single line of javascript, just the print statement.


Ok, it does print out in the console but I have no ideea why it didan't worked earlier......


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.