Second for loop


#1


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

what is wrong in this code. plz help me the error is
Oops, try again. 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.


#2

After testing your code I think your only error is in for(var i = 0; i > text.length; i++).
It should be for(var i = 0; i < text.length; i++) because if you say that i > text.length you actually say "Ok, run until this condition is true." and your condition is never true.


#3

Yaah! thank you so much.. im such an idiot i didnt saw that one.:slight_smile:
thank you!


#4

Don't worry, it happens. :wink: You got the harder part right and it's more important.


#5

yes you are right:) anyway thanks once again.


#6

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