5. Your second "for" loop - stuck on this!


#1


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


I'm getting stuck on placing my second for loop. Can anyone help please? I'm not sure what I've done wrong??


*jshint multistr:true */
var text = "Hey, how are you \
doing? My name is Jasmeet \
My name is Jasmeet.";
var myName = "Jasmeet";
var hits =[];
for(var i = 0; i < text.length; i ++) {
if (text[i] === 'J') {
for (var j = i; j < myName.length; i; j++) {
if (text[j] === myName[j-i]){
    hits.push(text[j]);
    }
}
}


#2

We can avoid this error by writing the offset first...

j < i + myName.length;

#3

I now get the message of 'unexpected input'

Pretty sure I've probably just messed up one line

/*jshint multistr:true */
var text = "Hey, how are you \
doing? My name is Jasmeet \
My name is Jasmeet.";
var myName = "Jasmeet";
var hits =[];
for(var i = 0; i < text.length; i ++) {
if (text[i] === 'J') {
for (var j = i; j < i + myName.length; j ++) {
if (text[j] === myName[j-i]){
hits.push(text[j]);
}
}
}


#4

The inner loop has no need for another if statement. Just push text[j] to the hits array.


#5

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