Practice makes perfect


#1

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

is it R8?????


#2

Hi the while statement has that structure

while(condition){
   #do something
   #stop the loop
}

#3

var count = 0
var looop = function(){
while( count<3){ #As long as count is less than 3, the code will run
console.log (I'm looping!"); # prints "I'm looping!" as long as the while condition(count<3) is true.
count ++; #ups count by one for each time the while condition is true.
}
}


#4

hey sayansayan,
first of all, you're missing a semicolon on the console.log.
And also, did you delete the last part where it calls the loop function?


#5

also seliunm,
you for got a semicolon for var count = 0.
you also added an extra o in loop.
did you delete the part where it calls the function?
I think count ++ belongs in the parenthesis of the while loop


#6

Hi everyone, can someone please explain how loop(); logs "I'm looping!” to the console ??

I made some notes below but I don't understand why this part is necessary..

var count = 0; //starts count at 0

var loop = function(){

		while(count < 3){ //will analyse values from 0 up to but not including 3

				console.log("I'm looping!");

				count++; //tells comp to add 1 each time function is called

		}

};

loop(); //logs "I'm looping!” to the console

#7

Nvm..

Found the answer here:


#8

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