I have been stuck on the second loop for so long and idk whats wrong


/*jshint multistr:true */
var text = "bruh my name is Andrew Andrew Andrew";
var myName = "Andrew";
var hits = [];
for (var i = 0; i < text.length; i++)
if (text[i] === "A")
for(var j = i; i < (myName.length + i); j++)


your loop condition:

i < (myName.length + i);

how will this cause your loop over instance of Andrew in text string?


I'm sorry I don't understand what you mean by that.


i am asking you to explain the condition of your second loop, so i can understand where you thinking is going wrong


so for(var j = i; i < myName.length + i; j++) should pick up from "A" which has been replaced withand will search for letters subsequently 1 at a time. I've seen other people do the same thing in the forum and none of the answers are helping me.


yes, but look at:

 i < myName.length + i

how can you use two times i here, so i has to be smaller then myName.length + i

you should j here at the right place, so your loop ends so you can loop from j till end of your name (myName.length + i)


ok thank you so much I didn't even realize I did that.


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