Not pushing values to "hits" array?


#1


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


I had some trouble with the second FOR loop, and corrected it, but now I'm getting the 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.

I've browsed similar questions looking for an answer to this, but I'm still at a loss with where to go from here. Any help would be greatly appreciated.

/*jshint multistr:true */
var text = "Some text with my name, Chris";
var myName = "Chris";
var hits = [];

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


#2

text[i] === myName.substring(0)

You just have to compare with first letter of your name.

substring gives part of string..

when you do this..

"Ryan".substring(0);
It means it will give you string from 0 to end index. aka ("Ryan")


#3

Right, that fixed it. Thanks!


#4

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