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


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++) {


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


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.


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