"Log it!" Wrong output?


#1


Hey guys, the code seems to be fine since it tells me " you've finished the course". But the output i get is just " [] ".
What's wrong here? Thanks for help!


var text =" hadbadb Joe csbdoaib bdcd dsbbcfh Joe hofwah Joe";
var myName ="Joe";
var hits = [];

for (var i = 0; i < text.length; i++) {
    
    if ( text[i] === "J") {
    
        
        for (var j = i; j < (i + myName.length); j++) {
            
            
            
        hits.push(text[j]);
            
        }
        
    }
    
}


if ( hits.length = 0) {
    console.log("Your name wasn't found");
}

else {
    console.log(hits);
}


#2

this line:

if ( hits.length = 0) {
    console.log("Your name wasn't found");
}

you set the length of hits to zero (single equal sign means assign) instead of comparing hits length with zero (two or three equal signs)


#3

Thank you, i could fix it know