Your second "for" loop


#1

Hi, could you help me to find a solution.
I really get stuck with this error. It should be okay, but it shows 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 = "Who are you";
var myName = "Kingking";
var hits = [];

for(var i = 0; i <= text.length; i++)
{
if(text[i] === "K")
{

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

};

console.log(hits);


#2

@byterunner16152
Try it including the name you are looking for
by using the text

var text = "Kingking Who are you Kingking";

#3

@leonhard.wettengmx.n
Thank you so much! it worked.
But, I don't know why my text didn't work, and your text did.


#4

@byterunner16152
How many hits would you have with your text with

if(text[i] === "K")

#5

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