Missed the problem


Your second "for" loop

The Error:
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.

/*jshint multistr:true */
var text = "I am Ofek. my mom pick Ofek as my name. my dad do not pick Ofek as my name";
var myName = "Ofek";
var hits = [];

for (var i = 0; i < text.length; i++) {
    if (text[i] === myName[i]) {
        for ( var j = i; j < myName.length + 1; j++) {


if (text[i] === myName[i]

Consider this,
By the time the first loop reaches your name, i is equal to 5 myName[5] is not valid.
We want to catch the first letter of myName, AKA myName[0]


solved the problem by changing
"if (text[i] === myName[i])" to "if (text[i] === myName[0])"
and "for ( var j = i; j < myName.length + 1; j++)" to "for ( var j = 0 ; j < myName.length + 1; j++)"

btw, the tutorial guide me to this - "for(var j = i; // rest of loop setup"
and make my mistake or i solved it another way.

any way VERY THANK YOU !! :upside_down_face:


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