5/7 .push() not working?


I keep getting an error message that 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.

not sure why its not working because as far as i can tell this code is similar to other resolved questions on the topic. would love help to clarify why its not working.

/*jshint multistr:true */
var text = "ifjeifjwe pablo ieijdwickl"
var myName = "pablo"
var hits = []
for(var i = 0; i > text.length; i++)
    if (text[i] === 'p')
        for (var j = i; j < (i + myName.length); j++)


take a close look at the conditon of your first loop:

i > text.length

hm.. i is 0 in the beginning text.length is roughly 40, 0 > 40 is false, loop ends without ever running.

your .push():


you use j to loop over your name, not i. so i would push text[j]


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