Your second "for" loop HALP!


#1

/*jshint multistr:true */

var text = "ello Hannah is a cool name so Hannah and Hannah";

var myName = "Hannah";

var hits = [];

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

}

there's probably something really obvious I'm missing, but its not working! Please help?


#2

if(text[i]=== H ) {
              ^

I believe that's supposed to be a "String", you don't have a variable named (var H = "something or other"")


#3

if(text[i]==="H")
Still isn't working.:confused:
it says,
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.


#4

Could you please post your updated code? I am not sure if another problem formed that I can't see yet.


#5

var text = "ello Hannah is a cool name so Hannah and Hannah";

var myName = "Hannah";

var hits = [];

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

}


#6

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

FOUND IT!!

i is not greater than the variable "text"s length, so the for loop will not run! :+1:


#7

THANK YOU SO MUCH (sorry it's been a week)
lolman to the rescue again!