Cant figure this out please help me out


#1

search text for your name lesson 7

The code runs and the lesson accepts it but all it prints are brackets [ ].


var text = "my name is sidney. my grandpas name is sidney";
var myName = "sidney";
var hits = []
for(var i = 0; i < text.length; i++) {
    if(text[i] === "s") {
        for(var j = i; j <(myName.length + i); j++) {
            hits.push(text[j]);
            
        }
    }
    
    if(hits.length = 0) {
        console.log("Your name wasn't found!");
    }
    else {
        console.log(hits);
    }
    
    
}


#2

= is an assignment operator

=== is a comparison operator


#3

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