5. Your Second 'For' Loop


#1


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


I do everything that the message asks me to (I believe), but it gives me the following error message every time:

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++) {
            hits.push(text[j]);
        }
    }
}


#2

Hello :slight_smile:

Second for loop is completely correct.

The condition of the first (outer) for loop is a problem, can you spot it?

Hint -> currently, body of the outer for loop will never be executed, because any non-empty text has length greater than 0.


#3

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