While loop not printing


#1

// Write your code below!
for(var i=0;i<2;i++){
    console.log("A for loop twice!");
    };
while(j>4){
    console.log("Only three while loops.");
    j++;
    };
do{
    console.log("Only one do loop")
    } while(j);

Tried to run my code as is. Printed the for and do loops fine, and let me finish the exercise, but my while loops are not going through. What am I missing?


#2

@speedyson,
You were Lucky that you did not define the variable j

for(var i=0;i<2;i++){
    console.log("A for loop twice!");
    }
var j = 1;
while(j<4){
    console.log("Only three while loops.");
    j++;
    }
do{
    console.log("Only one do loop");
    } while(j<2);

The Instructions:
To finish up and prove your loop mastery,
write three syntactically correct loops in the editor:
one for,
one while, and one do. Beware of infinite loops!

the for-loop:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for

the while-loop:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while

the do-while-loop:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/do...while

See how Javascript handles a Value in a place where it expects a condition
that results in a Boolean true or false
https://developer.mozilla.org/en-US/docs/Glossary/Truthy
https://developer.mozilla.org/en-US/docs/Glossary/Falsy


#3

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