# Exercise said I passed but I got a number as result. Is it right? - Exercise 5. Your second "for" loop

#1

Hi, guys!

It's me. Again.

I inputted the following code but instead of returning the letters inside my name, I received a "28" result (which is the count on all the letters that should appear).

What did I do wrong?

I received no error for this exercise but I think I did something wrong.

``````/*jshint multistr:true */
var text = "hahdasiudhasdasdas vanessa asdasd asdasd vanessa asdasdvanessa asdasdads vanessaasd";
var myName ="vanessa";
var hits = [];

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

Thanks for all the support!

#2

Add the keyword var before i = 0.

Your supposed to check for the first letter of the string you are trying to find so in this case your code wouuld be
`if (text[i] === "v")`

You don't need the parentheses before `myName.length` and you dont need to add it to i here `myName.length + i`

That's all you need to do.

#3

OK, adding the var statement worked!

Should't myName[0] be the same as "v"?

1) Parentheses: OK
2) Regarding the i variable, if I don't sum it to my name length when I get the next position it will sometime count my stop condition wrong, wouldn't it?
eg.: the fourth lookup under

A) With the + i, the j loop stop condition would stop under the 7+74th character (that would be "a"):

``````for (i=74; i<83; i++) {
if (text[74] === "v") {
for (j=i; j < (7 + 74); j++) {
hits.push(text[j]);
};
};
};``````

B) Without the + i, the j loop stop condition would stop under the 7th character (that would be "i"):

``````for (i=74; i<83; i++) {
if (text[74] === "v") {
for (j=i; j < (7); j++) {
hits.push(text[j]);
};
};
};``````

#4

Why this isnt the same is because you are trying to access a string the way you would access a list.

#5

No the reason you don't need = i is because you increment the loop by adding the second loop which actually points to your text. The loop will stop when all letters have been pushed to the empty list. `hits = []`

#6