HELP - IF statement inside FOR loop keeps going infinite


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/2/4?curriculum_id=506324b3a7dffd00020bf661

This function keeps going infinite. I'm trying to code a bit above the spec of the lesson, in that there is an if statement inside the for loop, but the syntax on both are correct as far as I can tell. Is there something special to consider when nesting like this, or am I missing something completely?

Thanks


var condition = false;
var i = 1

var test = function() {

    do {
        console.log("dogs");
        
    } while (condition) {
        
        console.log("lol");
        
    } for(i = 1; i < 7; i++) {
    
        if(i = 1) {
        
            console.log(i + " " + "dog");
    
        } else {
            
            console.log(i + " " + "dogs");
            
        }
    }
};

test();


#2

The reason is this:

 if(i = 1) {

And what do you try here?

while (condition) {
        
        console.log("lol");
        
    }

#3

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