5. Don't understand what's wrong with the "Seconf 'for' Loop"


Hello everyone! I'm so very stuck with this one. Please help!


This is the error I keep getting:

"Oops, try again. There was a problem with your syntax."

i r/*jshint multistr:true */
var text = "Hey, what are you\
a rat m8? My name is Emily. I'm not Ilya\
, I am a computer robot, whos Ilya??";

var myName = "Ilya";
var hits = [];

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



Here, remove the space between the ++ and j because we are incrementing. It was probably an error of typo.



i r at the beginning of your code
for code readabillity use i++ and j++


Remove space to become j++

Also, you've got curly braces I find needless. Look through!

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


Thank you! It helped :slight_smile:


You're welcome.

Have fun coding! :smile:


What does the "j" mean in this instance?


j is another variable we've to loop through i.


Hey guys! Can you plz figure out the problem with my code..Its as follows:
/*jshint multistr:true*/
var text,myName,hits;
text="This is Aman. I love coding. Aman loves to code.";
hits = [];
for(var i=0;i< text.length ;i++)
for (var j = i; j < i + myName.length; j++)

Error: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.



Have a close look at



Got it! Thanks.:slight_smile:


Why does j equal i? and what does j stand for?