(Your second "for" loop) no clue what i'm doing wrong


#1


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


/*jshint multistr:true */

var text = "Hey, Michael! Just a reminder that your name, Michael, is a little to awkward to say, Michael, so we have all decided to start calling you, Mikey!";
var myName = "Michael";
var hits = [];
for (var i = 0; i < text.length; i+=1) {
    if (text[i] === 'M'); { for 
    (var j = i; j < (i + myName.length);) {
        myName = [];
        myName.push("Michael");
        myName[0] = ("M");
     
}


#2

You don't need a ; between your ) and { in your if statement. Also in your for loop, you need to add a counter that you're missing.

for(var j = i; j < (i + myName.length); j++){

}

Also you have the wrong stuff in your for loop. You should just be taking text and pushing it to hits. hits.push(text[j])


#3

thanks, i was stuck and really confused!


#4

I'm stuck on this, too. What is j?


#5

j is a variable representing the loop iterator beyond i that is intended to find the length of myName. How exactly to do that, I have no idea.


#6

hii,can you help me out...
for(var i=0; i<text.length;i++)
{
if (text[0]===myName[0])
{
for( var j=i; j<=(i+myName.length); j++)
{

        hits.push(text[j]);

         }

}
}
whats wrong???


#7

hii,can anyone tell whats wrong...
for(var i=0; i<text.length;i++)
{
if (text[0]===myName[0])
{
for( var j=i; j<=(i+myName.length); j++)
{

        hits.push(text[j]);



    }
}

}


#8

@coresolver71172,

if (text[i]===myName[0])

#9

this error is displayed-Oops, try again. Make sure you're pushing letters to the hits array


#10

for(var i = 0; i < text.length; i++) {
   if (text[i] === myName[0]) {
      for( var j = i; j < (i + myName.length); j++) {  // I changed <= to <
         hits.push(text[j]);
      }
   }
}

I checked this code and it works. Please try again.


#11

yap...thnxxx...i did some sillymistake...


#12

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.