What am i doying wrong?


#1

I do not know what am doing wrong. Can some guys help me out?

 /*jshint multistr:true */
    var text= "Oliver is cool. Oliver is een goede leerling. Hij smurft graag Oliver";
    var myName = "Oliver";
    var hits= [];
    for( var i = 0; text.length < i; i++){
        if (text[i] === myName[0]) {
            for(var j = i; j < (myName.length + i); j++)  {
                hits.push(text[j]);
            }
        }
    }

#2

@wecodetogether this is your code corrected check out the comments to understand where the errors were erere

    var text= "Oliver is cool. Oliver is een goede leerling. Hij smurft graag Oliver";
    var myName = "Oliver";
    var hits= [];
    
    // here the condition should be
    // i <text.length not the other way
    for( var i = 0; i <text.length; i++){
        if (text[i] === myName[0]) {
            //defined this temporary variable
            //it will store the substring i look for
            // when i find the first letter of myName
            // look ahead to chack for a match
            var found = "";
            
            for(var j = i; j < (myName.length + i); j++)  {
                   found+=text[j];
                   
                   //debugging statement
                   console.log(found);
                if (found === myName){hits.push(found);}  
            }
        }
    }
    
console.log(hits);