Practice makes perfect


#1

Not sure what to do here, here is my code so far:

//Remember to set your condition outside the loop!
var count = (count++)

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

Instructions:
Write a while loop that logs "I'm looping!" to the console three times. You can do this however you like, but NOT with three console.log calls. Check the Hint if you need help!


#2

This will raise an exception since count is not defined yet when being referred. When declaring it, we initialize the value to 0.

var count = 0;

Now since this is a locally accessed variable, we will write it inside the function.

var loop = function () {
    var count = 0;
    while (count < 3) {
        // increment count

        // log a phrase
    }
};

#3

will try that, thanks for your help


#4

So far, I have this:
Remember to set your condition outside the loop!

//Remember to set your condition outside the loop!
var loop = function() {
var count = 0;
while (count < 3) {
count ++
console.log("I'm looping")
}
};

but it still is'nt working, not sure where I went wrong


#5

Did you try calling the function?

loop();

What error message are you getting?


#6

var count = 0;

var loop = function(){
while(count < 3){
//Your code goes here!

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

};

loop();

Try this!. And it generates a warning even for the string being displayed is different


#7

The condition should be outside the loop, mate.

var cond = 0;

var loop = function(){
while(cond < 3){
//Your code goes here!
console.log("I'm looping!");
cond+=1;
}
};

loop();


#8

So I added the ' loop()' so this the error message I get:
Oops, try again. It looks like you're not printing the right string to the console.

This is what my code looked like:
//Remember to set your condition outside the loop!
var count = 0;

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

The results:
I'm looping
I'm looping
I'm looping


#9

Still not getting it for some reason


#10

Write a while loop that logs "I'm looping!" to the console three times.

Be sure to copy exactly the text given in the instructions.


#11

Always remember that exclamation mark "!". That always gets me :frowning:


#12

OMG thanks, that's annoying :joy:


#13

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