Cant push array


I dont seem to be pushing the array to hits even though when i read through every single help post I see that I have practically written the same thing but it doesnt work

/*jshint multistr:true */
var text = "this is a stupidly long text with the words Jose just to test javascripts capabilities"
var myName =  "Jose"
var hits = []
for (var i = 0; i > text.length;i++)
    if (text[i] === myName[0])
        for(var n = i; n < (i+myName.length);i++)


your second for loop, why do you have i++?


because it has to go through every one of the letters of my name, do you know what is wrong with the push command?


but you use n to through every one of the letters of your name in text? (talking about second for loop)

There is nothing wrong with your push, you have a problem in the loop


what is wrong with my loop then?, and why does it report it as a problem with my push


OH i see i need to replace i with n (second loop)


nope still same error


you also have a problem in your first loop:

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

look at the condition, see a problem?


wrong sign causes an infinite loop?


now it worked thank you


the loop will evaluate to false the first time the condition is tested, so the loop never runs.


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