Assignment in conditional expression


#1

The very last line of code has a yellow triangle in front of it telling me that "Assignment in conditional expression", I don't know how to fix this only that my code runs for ever.

// Write your code below!
var forLoop = function(){
for(var i=1; i<11; i++);
};
forLoop();

var whileLoop = true;
while(whileLoop){
console.log("This is my while loop code!");
}
whileLoop();

var whileCondition = false;
do{
console.log("I'm printed once!");

}while(whileCondition=false);


Replace this line with your code.


#2

Link the exact problem page.
Ok I'm going to debug your code..
Lets do it by dissecting each part of code.

This is your code.

// Write your code below!
var forLoop = function(){
for(var i=1; i<11; i++);
};
forLoop();

var whileLoop = true;
while(whileLoop){
console.log("This is my while loop code!");
}
whileLoop();

var whileCondition = false;
do{
console.log("I'm printed once!");

}while(whileCondition=false);

Problem 1.

You have put colon there.
You're not using your loop to print something ?

// Write your code below!
// This prints 1-10
var forLoop = function(){
for(var i=1; i<11; i++) {
    console.log(i); 
   }
};
forLoop();

Problem 2.

It's an infinite loop. (This is actually making your code go unresponsive!)
whileLoop is not a function.
The condition inside the while loop is always true.
What we can do ?

var whileLoop = true;
while(whileLoop){
    console.log("This is my while loop code!");
    whileLoop = false;
}

do..while works fine...
I hope it helps! :slight_smile:


#3

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