Your second "for" loop


#1

what is wrong with this?

/*jshint multistr:true */
var text = "hi everyone i am sAeed mazarei. \
i am a programmer and designer. thank u sAeed";
var myName = "sAeed";
var hits = [];
for (var i=0 ; i<text.length ; i++) { 
    if(text[0]===myName[0]) {
        for(var j=i ; j<(myName.length+i) ; j++){
            hits.push(text[j]);
        }
    }
}


#3

This if condition won't trigger your 2nd loop. Text[0] corresponds to the 1st character in your text string 'h'. The 1st character of the myName variable is 's'. They will never be the same. You need to give the if statement a condition that will trigger your second loop.


#4

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