Your second "for" loop - not sure what's wrong


After looking at numerous other posts and trying many variations, I still can't get past this part. Not sure where my error is. Thanks for your help!

Error message: "Oops, try again. It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable."

/*jshint multistr:true */
var text = "Hey Joe, where you goin' with that gun of yours? \
Hey Joe, I said where you goin' with that gun in your hand? \
I'm goin' down to shoot my lady, \
You know I caught her messin' 'round with another man.";

var myName = "Joe";

var hits = [];

for (var i = 0; i < text.length; i++) {
    if (text[i] === 'E') {
        for (var j = i; j < (myName.length + i); j++) {


The idea is that the if statement finds the first letter of your name, of Joe, this is J, not E


And that's an excellent reason why you should not hard-code anything, but instead use the language to get the data you need "the first character of your name" -> name[0]

This way, if you change data somewhere, the rest of the code will still act the way it is meant to.


Ah thanks so much! It works now!

I looked over the code so many times... can't believe it was just a dumb error like that.


i would follow @arcplayer05261 suggestion if i where you, it is better practice