Can't figure out why the code isn't accepted


#1


https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661#


It's saying to make sure I'm pushing my hits to the hits array and I know something is wrong I just can't tell where. The whole "(var j = i; j < (i + myName.length); j++)" is confusing to me if I try to map what's happening in my head so if you could help me understand that a little bit better, that'd be awesome haha!


var text = "Blah blah blah blah blah blah Eric \
blah blah blah Eric blah blah Eric blah blah \
blah blah blah blah blah Eric";

var myName = "Eric";
var hits = [];

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


#2

Ended up changed the 12th line to " hits.push(text[j]);"... still anyways is that correct way I should have done it?


#3

Yes, that is the correct way. We are pushing a single character at index position j of text.

For practice, go back to lesson 2 and try this from scratch to reinforce the lessons learned.


#4

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