5. Your second "for" loop


#1

Hi there: Can someone please help me out with my syntax? I have been searching for my error and I still can't find it! Thanks in advance!!

/*jshint multistr:true */

var text = "Olivia it is hot out and summer is almost over Olivia school starts in a few weeks and I need to finish my summer homework Olivia";
var myName = "Olivia";
var hits = [];

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

#2

What's it doing different from what you want? The syntax is valid.


#3

this is the error it is giving me:

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


#4

Then you'd start by confirming whether it did or did not push values to that array by adding a print at the bottom.

And then if you agree with that error message you can start considering why it would have added to the array and investigate how far it got in doing that, and where it's doing something differently that you need to adjust.


#5

Ok, thank you for your help!


#6

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