Can someone please help, I have checked this code over and over


#1


https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661#


Error Code I'm getting is "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."


/*jshint multistr:true */
var text = "this is the string that I'm using, Michael, to test\
if it can detect your name, Michael";

var myName = "Michael";

var hits = [];

for (var i = 0; i < text.length; i++) {
    if (text[i] === "M") {
       
       for (var j = i; j < (myName.length + 1); j++) {
           hits.push(text[j]);
           console.log(j);
           
} 
}
}


#2

nevermind I was adding "1" instead of "i" to the second for statement!!! UGH stupid similar looking characters!


#3

Hi @arcjumper73595,

Other than that, just want to point out,

       console.log(j);

is not needed in the exercise.

:slight_smile:


#4

yeah, I only added that in there during my troubleshooting phase because I saw others had it lol
Obviously it didn't help :sweat_smile:


#5

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