Second 'for' variable not pushing values to hits array


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++) {
if(text[i]=== "A") {
    for(var j = i; j < (i + myName.length); j++) {


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


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."


Remove this section of your code.


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


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.


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


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