Cannot find my error


#1


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


My browser keeps crashing so I am pretty sure I did the second for loop incorrectly. I have been checking out the other posts and I cannot seem to figure out my error. Any input is greatly appreciated!


/*jshint multistr:true */

var text = "Hey, how are you \ doing?  My name is Kay.";

var myName = "Kay";

var hits = [ ];

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


#2

Missing Brackets in for loop "j=i+myName.length" and condition

Correct your code to


for (var j=i; j<(i+myName.length); j++)

You don't need the brackets in condition, but its good to have one if there are multiple conditions involved.


#3

for (var j=i; j=i+myName.length; j++)

You need to but < instead of = in the second part of the for loop. You want to run the loop while the index j is less than the length of myName.

(And you don't need the brackets like the previous answer said.)


#4

Awesome and thank you guys!


#5

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