Stuck on 2nd for Loop also


#1

Hi, I'm frustrated. Here is my code (written for the millionth time):

/*jshint multistr:true */
var text = "Hi my name is Brock. Isn't Brock a cool name? I like the name Brock."
var myName = "Brock"
var hits = []
for (var i = 0; i === text.length; i++)
{
if (text[i] === "B")
{
console.log("I am Brock. I love to say: " + text);
for (var j = i; j < (i + myName.length); j++)
{
hits.push(text[j]);
}
}
}

here is the error message I keep getting.

"It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable."

Can anyone please please help? Thank you!


#2

for (var i = 0; i === text.length; i++)
                  ^

The issue is that i will never be equal to text.length since it's initiated as 0. So make it so the condition encompasses " i ".


#3

How would I do that?


#4

I figured it out. Thank you so so much!!