5. Your second "for" loop | It looks like your second 'for' loop isn't pushing values to the hits array


#1

What's wrong with this code?

for (var i = 0; i < text.length; i++ ) {}
if (text[i] === 'M'){
for (var j = i; j < i + myName.length; j++) {
hits.push(text[j])
}
}


5. your second "for" loop
#2

Hi you should close } you first for loop after your if statement


#3

like that?

for (var i = 0; i < text.length; i++ ) {
if (text[i] === 'M')}{
for (var j = i; j < i + myName.length; j++) {
hits.push(text[j])
}
}

now it changes to Syntax Error


#4

no like that

for (condition) { //first for loop
    if (condition) { //if statement
        for (condition) { //second for loop

        } //close the second for loop 
    }//close the if statement
} //close the first for loop

#5

thanks for help :tada:


#6

why (j < i+myName.length)?


#7

when ever I click save and submit and shows nothing in the console. Can someone help me?


#8

A post was split to a new topic: Don't know what's wrong about this


#9