Your second "for" loop -- push letters instead of numbers


#1

I'm pretty sure that I have almost everything for 5. Your second "for" loop correct, but I don't understand how to push letters instead of numbers. I know that hits.push(j) is wrong, but I don't know what's right. Can anyone take a look at my code and explain what I'm missing?

var text = "My name is Kelsey and I am supposed to write a long sentence or two with my name, Kelsey, sprinkled in once or Kelsey twice.";
var myName = "Kelsey";
var hits = [];
for (var i = 0; i < text.length; i++){
    if (text[i] === myName[0]){
        for (var j = i; j < i+myName.length; j++){
            hits.push(j);
            console.log(hits);
        }
    }
}

#2

j is just the index, we can use indexes to access letters inside strings. Of which string do you need the letters? In this case, the string stored in text. Remember how to use indexes to access items inside strings?

Does that help?


#3

I do not remember that at all... I thought maybe you were talking about using get, but hits.push(text.get(j)); doesn't seem to do the trick either.


#4

let me help you a little:

console.log("hello"[0]);