6/7 Not printing correctly but accepted


#1

Hi everyone,

When I run this code, all I get in the viewer is " 'E' "

The exercise accepted it but I don't think it's right. It's not printing out all the letters in the name. Why not?

var text = "Hey, Elaine how are you doing? my name is Elaine.";
var myName = "Elaine";
 var hits = [];

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

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

#2

Hi in this hits.push(text[i]); you should put inside [ ] "j" like that

hits.push(text[j]);

#3

That worked, thank you!:+1: