Hello everyone, can someone help me to figure this trick


#1

hi there can you explain to me how this code gets "a way to go "
var count=0

var loop = function(){
while(count>3){

}

};
and am supposed to log three statements but i did not i just set the counter

and when i entered this code
var count=0

var loop = function(){
while(count>3){
//Your code goes here!
console.log("I'm looping!");
count++ ;
}
};
i get this error "Oops, try again. Are you logging 'I'm looping!' to the console three times?"
any ideas ???


#2

while(0>3)

should it be run??

also you have to call the function after closing the function.


#3

i don't know, i will try.
but how this strange code pass !!! i still did not figure it out
can you tell


#4

please post you update code.


#5

yap it worked also:
var count=0
var loop = function(){
while(0>3){}
};
Way to go! Start Next Lesson


#6

may be you paased the lesson but loop is false :slight_smile:


#7

right ? that's why am putting this question i want to know how this code passed
am asking my friends around , but i did not get a good answer yet


#8

The while loop loops through a block of code as long as a specified condition is true.

in your code
while(0>3)
is false.so it'll not run.is 3 less than 0?your condition should be true.
write
while(0<3)
then it'll run and print I'm looping!
and

count++ ; //here now count is 1
now it'll check
while(1>3) //true so it'll run agian
so on.

now what about function?you have to call the funtion to make it any use.it doesn't execute when you declare it.so call the function at the end with function name.in your case
loop() //calling the function


#9

thank you very much 'rcodeman' this is a very helpful explanation thanks you again


#10

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