Second 'for' variable not pushing values to hits array


#1


I've seen every post related to this topic, copied correct codes, yet it isn't working. Can someone pls tell me whats wrong. Its been 3 days.


var text = "hey, how are you \ doing? My name is Avisha \ I live in Singapore! \ did I mention my name is Avisha?";
var myName = "Avisha"; 
hits = []
for(var i=0; i < text.length; i++) {
    console.log(i)
}
{
if(text[i]=== "A") {
    for(var j = i; j < (i + myName.length); j++) {
    hits.push(text[j]);
    }
}
};


#2

What kind of error did you get? It would be easier if you could give a reference to that task.


#3

Hi, I got "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

Remove this section of your code.


#5

OMG! yes it worked.
Thank you so much!!!


#6

I'm glad it worked :slight_smile:

With the 1st for loop closed off, the 2nd for loop wasn't being triggered. The goal is to have the 2nd for loop execute when the 1st loop runs and comes across the "A" in the myName variable.


#7

That makes so much sense. :smiley: I'll keep that in mind!


#8

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