Your second "for" loop


#1


Dont know what is wrong with this code

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

It gives an error saying "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"

What should I do?


#2

https://discuss.codecademy.com/t/your-second-for-loop/54974/2 I would suggest looking at this discussion above ^


#3

Hi you should put at least once your name inisde the variable text

var text = "Hello";

#4

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