Cannot find my error


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++)


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.


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.)


Awesome and thank you guys!


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