#5: What is my mistake and how to fix it


#1

Here is part of my code:

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

I've looked for an answer to my problem on the forums, but it seems I can't find a solution to the problem. I think the problem is that I did the push method wrong? I don't completely understand why I'd be pushing a variable representing a number to the hits array.

Please tell me what I did wrong,no spoilers, and how to fix it. If you need/want to see more of the code, tell me.


#2

im not a pro yet and still learning. But line 3 what does J = to? it says j=; should be = to i?


#3

Hi first here

for(j=; j===(i+myName.length); j++)

Like @cssplayer42079 said you should put j = i An d then here

j===(i+myName.length)

You should put j less than i+myName.length like that

j < (i+myName.length)

So this part should be like that

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

#4

you haven't declared j "(j=;" should be more like "(var j=1;"
then you have said while j equals i+myName.length, it will only equal myName.length+i once when you have completed a match so you want it to say j < myName.length then you need to cycle through the characters by using text[i+j]===myName[j]

hope that helps i've got mine to work but it's complaining even though it works. lol


#5

Thanks guys. I swear I had fixed that semicolon.... :neutral_face:
I can't believe i forgot to declare j as a variable! I guess I haven't fully come back from my vacation from Codecademy.