Is this correct?


#1

In the exercise I had to just create a random for loop and a random while loop myself. I did the following and the exercise said well done go to the next exercise, but nothing was actually printed to the console. Is this a glitch or am I actually doing something wrong?

var count = true
var forLoop = function(){
    for(i = 0; i < 10; i++){
        console.log("This is never going to work!");
    }
}
var whileLoop = function(){
    while(count){
        console.log("No chance at all!");
        count = false
    }
}

#2

you use functions, which is fine and perfectly valid, but in order for a function to execute, you need to call the function

Given you don't call the function, they won't execute, so there is no output

if you want output, call the functions


#3

Wow, of course! Can't believe I didn't notice that, thanks :slight_smile: So basically it would have to be like this:

var count = true
var forLoop = function(){
    for(i = 0; i < 10; i++){
        console.log("This is never going to work!");
    }
}
var whileLoop = function(){
    while(count){
        console.log("No chance at all!");
        count = false
    }
}
forLoop();
whileLoop();

#4

That should do the trick, now you should have output :slight_smile:


#5

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