5. Your second "for" loop


#1

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

A message keeps coming up saying that I have a syntax error. Any suggestions?


/*jshint multistr:true */

var text = "The name is Lindsay. Lindsay enjoys reading books. Lindsay also likes running.";
var myName = "Lindsay";
var hits = [];

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


#2

I see two problems in your code. In second inner for loop you should remove comma in second statement.
And should push values to hits array and not hit because it doesn't exist.


#3

It seems that you have a typo in the second for loop's code block

Use hits.push(text[j]) instesd of hit.push(text[j])


#4

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