Your second 'for' loop isn't pushing values to the hits array


#1



Hi Guys ! Please, help. My code looks exactly like those provided in the forum that work . Though mine doesn't . Can't find the bug

https://www.codecademy.com/en/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661#


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.


var text =  "I'v got a gun Ed " ; 
var myName = "Ed";
var hits = []; 
for ( var i= 0; i<text.length; i++); {
    if ( text[i]==='E') {
        for ( var  j = i;  j < (myName.length+i); j++) {
             hits.push(text[j]);
    }
    }
    }


#2

this line:

for ( var i= 0; i<text.length; i++); <- this one

the last semi-colon is wrong, it prevents the loop from executing properly


#3

var text =  "I'v got a gun Ed " ; 
var myName = "Ed";
var hits = []; 
for ( var i= 0; i<text.length; i++); {  // why ; remove that
    if ( text[i]==='E') {
        for ( var  j = i;  j < (myName.length+i); j++) { 
             hits.push(text[j]);
         }
    }
}

@stetim94 was quicker :slight_smile:


#4

Everything is so simple ! Thank you guys ! :slight_smile: