5 int for loop


#1

var text = "Hey,how are you\
doinh? My name is Emily?"
var myName = "Emily"
var hits = []

for(var i=0;i<myName.length;i++){
    if (text[i] === "E"){
        console.log(text[i])
        for(var j=i;j<i+ text.length;j++){
        hits.push(text[j])
          console.log(hits)
              
              }
          
            }
            
}

I am not sure what is wrong in here.


#2

I think You mixed up the two loops.

The first loop has to loop over length of text where as the second loop should loop over length of myName starting from index it catches the first letter of myName.


#3

This change worked. Thanks!


#4

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