'for' loop isn't pushing values


#1

Is someone able to point out to me why it doesn't add to the area. Thank you for you help.

Error:"
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."


var text = "agdk Otto sdfjki Otto dlsafljs Otto alsflj flsjlflaj adsf Otto alfsdjl";
var myName = "Otto";
var hits = [];
for (i = 0; i < text.length; i++)
{ if (text[i] === "O")
for (j = i; j < text[i]+myName.length; j++) {
hits.push (text[j])
}
}


#2

Needs a slight change,

    j < i + myName.length;

#3

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