Loop help


#1

This loop is not stopping where I need to. Any suggestions?

var text = "hello everyone Mick is the the house \
and he is living life large like a Mick should";
var myName = "Mick";
var hits = [];
for(var i = 0; i < text.length; i++) {if(text[i] === "M");
{for(var j = i;j < myName.length; j++) {hits.push('Mick')}}
}

Much Appreciated.


#2

Hi @pysolver61646

Check this and see your mistakes :

var text = "hello everyone Mick is the the house \
and he is living life large like a Mick should";
var myName = "Mick";
var hits = [];

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

console.log(hits);

Hold on :wink:


#3

Hi, thanks for your help.