Practice Makes Perfect


#1

Hello,
While doing "5.Practice Makes Perfect" part, got some question in my mind.
Can someone please explain what are differences among the codes below:
NOTE: first once is correctly loading while others not.

In the first code, I know that we giving function to "count" and everything else starts after 1st line. But why, we cannot use $(document).ready(function) { } for the same purpose?

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

////////////////////////////////////////

$(document).ready(function) {
var count = 0;
while(count < 3) {
console.log("I'm looping!");
count+++;
}
};

count();

/////////////////////////////////////////

var count = 0;
$(document).ready(function) {
while(count < 3) {
console.log("I'm looping!");
count+++;
}
};

count();

///////////////////////////////////////

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


#2

The only differences in all the codes above is that two of the scripts are,

Two of the codes above are Jquery and two others are Javascript but still do not forget that jquery is a Javascript library meaning all the codes above do perform the same action which is stop looping if count < 3


#3

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