The code works, but doesn't show the individual letters


#1

It shows up like [ 'Musab', 'Musab', 'Musab', 'Musab', 'Musab' ], but how would I change it so that the hits array has the indivisual letters of my name, not my full name repeated as many times as its length.

var text = "Hello, my name is Musab Abdullah \ I am a chicken nugget."
var myName = "Musab"
var hits = []
for (i=0; i<text.length; i++)   {
    if (text[i]==="M")  {
        for(j=i; j<i+myName.length;j++) {
            hits.push(myName)
        }
    }
}
if(hits===0)    {
    console.log("Your name wasn't found!")
}
else    {
    console.log(hits)
}

#2

Hi this part

if(hits===0)

You should put the if the length of hits is equal to 0

Then here

hits.push(myName)

You should push inside hits text[j]


#3

Here is the place you should change.


#4

I'm having the same hassle and the code is as instructed above:

var text = "Victor. Viktor. Vase. vase. Victor. Vincent. Volcanoe. You shall not pass!";
var myName = "Victor"
var hits = []

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

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