5. Your second "for" loop: Still need help


#1

I actually still do not understand how my code is incorrect now. I did a past topic talking about this, thinking I got my code correct, but it still says the same error message. I checked another person's and it was exactly the same. Please help me.

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.


var text = "Well, hello. How are you today";

var myName = "[CENSORED]";

var hits = [];

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

Please help me! Thank you.


#2

That sounds like something you can confirm by printing out that array


#3

I typed down console.log(hits)

Screen:

[]

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


#4

And then you can consider why it would have been pushing values into that, and check whether it did those things.


#5

The only differences I can see are:

line 1 most have your name (CENSORED) listed three times.

last line: I only have the close }

Good luck!


#6

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