Need help with second for loop


#1

Second for loop

cant push text t to array


/*jshint multistr:true */
 var text = "blah blah";
 var myName = "yusuf";
 var hits =[];
 
for (var i=0; i<text.length; i++) {
    if (text[i] === "y") {
    for (var j = i; j <(myName.length + i); j++) 
    {
    hits.push(text[j])
    
    }
}
}


#2

your name should also be in text, otherwise there is nothing to find


#3

I changed the var text to my name but still nothing has changed


#4

then it should be good, can i see an updated version of your code?


#5

/*jshint multistr:true */
var text = "blah blah";
var myName = "yusuf";
var hits =[];

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

}

}
}


#6

/*jshint multistr:true */
var text = "yusuf";
var myName = "yusuf";
var hits =[];

for (var i=0; i if (text[i] === "y") {
for (var j = i; j <(myName.length + i); j++)
{
hits.push(text[j]);
it works now thanks man
}
}
}


#7

the first for loop + if condition was good:

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

and then you ruined it, no wonder it is no longer working.


#8

lol i was copying the wrong thing into the forum but it works now, i kept thinking it cant search though text var if the letters dont match up