7. I need help turning repetitive code into a loop


#1

So I figured out how to keep the code from adding names that start with the same letter in my name but I think I could simplify it into a loop. I'm not really sure how to turn it into a loop. Help is appreciated. Here is my code:

/*jshint multistr:true */
var text= "Matt is Mantastic and Matt is Matt."
var myName= "Matt"
var hits= []

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

if (hits.length === 0) {
console.log("Your name wasn't found!");
} else {
console.log(hits);
}


#2

add else one
x=x+1
if (text[i+x]===myName[x]) {


#3

I'm not really sure what you mean @rubysolver95786