[Question] Search Text for Your Name: Log it!


#1


Search Text for Your Name: Log It!


For my console response I am getting ['A', 'A', 'A', 'A'], I thought that it was supposed to spell out "Alex" when all said and done.. Any ideas what's going on? Did I do something incorrectly?


var text = "Alex, Nicky, Boo";
var myName = "Alex";
var hits = [];
    for(var i = 0; i < text.length; i++){
        if(text[i] === "A"){
           for(var j = i; j < i + myName.length ; j++){
           hits.push(text[i])
           } 
        }
    }/*jshint multistr:true */
if(hits === 0){
    console.log("Your name wasn't found!")
}
else{
    console.log(hits)
}


#2

here:

hits.push(text[i])

you push text[i] to hits, why? j loops over your names once found


#3

Got it, thanks for the quick reply :slight_smile:


#4