[HELP]- 5/7 very rare output of hits array


#1
> /*jshint multistr:true */

> var text = " Hello my name is Frosti, yeah you heard it right, it's \
> Frosti , you're godamn right, Frosti it is!  ";
> var myName ="Frosti";
> var hits = [];
> var longitude = text.length;
> var nameLength =  myName.length;

> for (var i=0; i < longitude; i++)
> {
>     if (text[i] === myName[0]);
>     {
>         for(var j = i; j < (nameLength + i); j++)
>         {
>             hits.push(text[j]);
>         }
>     }
> }
> console.log(hits);

Hello, Im having trouble with this lesson, when I print the hits array I get a really weird output with what it looks like all the text repeated several times in block of 5/6 letters. Is there any mistake in my code?

thanks a lot for helping.

Solved: the semicolon after the first if was the problem


#2

@inak1,

Your code seems to b ok...

Try changing the text
like

var text = " Hello my name is Frosti, yeah you heard it right, it's Fun \
Frosti , you're godamn right, Frosti it is!  ";

#3

It doesn't work either, what's your thinking behind that though?


#4

So basically what is happening is that every

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

gets a true value, and I dunno why,I'm literally printing on console both characters and an "s" with an "F" gets true and enters the loop, any idea why?


#5

You will have to change that into

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

I'm so sorry that i didn't see that in the first instance...

From the wording in your Original Post,
i thought you were surprised
to see

[ 'F', 'r', 'o', 's', 't', 'i',
  'F', 'r', 'o', 's', 't', 'i',
  'F', 'r', 'o', 's', 't', 'i' ]

that's why i suggested to put in the 'Fun' word,
so you would see that the flaw of this code
lies in the fact you are checking on the first-letter of myName

[ 'F',  'r',  'o',  's',  't',  'i',
  'F',  'u',  'n',  ' ',  'F',  'r',
  'F',  'r',  'o',  's',  't',  'i',
  'F',  'r',  'o',  's',  't',  'i' ]