Cant push array


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661

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++)
        {
            hits.push(text[n]);
        }
    }
}


#2

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


#3

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


#4

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


#5

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


#6

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


#7

nope still same error


#9

you also have a problem in your first loop:

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

look at the condition, see a problem?


#10

wrong sign causes an infinite loop?


#11

now it worked thank you


#12

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


#13

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