Why do need a "function" with the while loop?


here's my code with no function:

var count = 0;
while(count < 3){
console.log("I'm looping!");
count += 1;

It's NOT perfect because it prints the integer 3 before code terminates!
is that why the function?



++++ why second display of last Item
It is the Javascript interpreter which is running in this course-environment,
it display's the last non-displayed action...

You will also encounter this, when you are doing a return-statement
as last action...
You could counter this by using a
console.log( " " ); as last statement....

In some sections of this course, the course-checker Display's data
this you could then identify by placing to EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );



They try to demonstrate,
that you can access AND modify a so-called =global= variable count
from within a function with it's FUNCTION-BODY

closure scope hoisting


Thank you Leonard!
I am understanding better, the more I practice.
thanks again for your help.