11/11 Why is "Here it is" not printed 3 times?


#1

It let me go through but I wanted the string "Here it is" to be printed 3x. Can any1 explain?


#2

Forgot code:

var array=["Hey", "Tom", "123213", 34]
 for(i=0;i<5;i++) {
    console.log(array[i])
 }
var cool=0
 while( cool<10) {
    console.log("Here are 10 strings")
    cool++;
 }

var doWhile=function(number) {
    do{console.log("I'm going to do next "      + "string " + number +   " times")
    }
    while(doWhile<6) {
        console.log("Here it is ")
    doWhile++
    }
};
console.log(doWhile(3));

#3

The problem is that this is not how a do while loop works:

do{console.log("I'm going to do next "      + "string " + number +   " times")
}
while(doWhile<6) {
    console.log("Here it is ")
doWhile++
}

This is your do while loop:

do{console.log("I'm going to do next "      + "string " + number +   " times")
}
while(doWhile<6)

Which would be an infinite loop if you'd taken the number parameter (as you probably intended) instead of the function name doWhile (don't take function names as anything other than function names). And this:

{
   console.log("Here it is ")
   doWhile++
}

is just regular code that is executed after the loop is finished! So what you need to do to make this work is to replace the function name with your parameter and to move the ++ part inside of the do/while loop. And maybe move the console.log message in the function before the function as you only want to see it once, do you?