5- your second 'for' loop



I can't find anything wrong with my code, but I keep getting this 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 = "meoanfwojrngfsong os gfso gsojrn andi fosrn fsoj gos jvsoj frvos \ sjdkl gfsgfnssljfn ls vs jlsf vls vsl vadjl felf l a andi sgn lfsjv ] \  kdvslfjkn andi andi s djad kfj jg ds anANDI  FJSF SLKJ FA L  jf sdfo wlj";
var myName = "andi";
var hits = [];

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


Easy mistake.

for (i = 0; i > text.length + 1; i++) this is saying while i is bigger than text.length + 1. When it should be saying while i is smaller than text.length + 1.

Simply change this > to <.

If this was the solved your problem please mark my reply as the solution.


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