Your second "for" loop


#1


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


Second for loop isn't pushing values to the array. Can't seem to identify the problem.


var text = "Hey it's your boy Minki. \ How you doing Minki? \ Minki is so cool. \ Minki is going to be great.";
var myName = "Minki";
var hits = [];

for( i = 0; i < text.length; i++); {
    
if (text[i] === myName[0] ) {
    
    for (j = i; j < i + myName.length; j++); {
        
     hits.push(text[j]);
    
     }
     
     }

}


#2

if (text[i] === "M")

also don't put a semi colon after your for conditional. Semi colon's never go after stuff like that.

Doing if (text[i] === myName[0]) doesn't work because the text in myName is not the same as in text. So using an index to find the first letter of your name won't work.

if(text[18] === myName[0]) doesn't work because it's grabbing the index number, not the value of it which is "M", from what I understand anyway.


#3

awesome thanks so much!


#4

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