5. Second for loop


Help me. What is wrong in my code?

var text = "hghfjhf jfdh djdfj ijhdj jgdjdj jdjk dgdg dfhd djhfdjh difhdhf fdf Pamela dsjb fjdkj Pamela dgshjfjhfhj hf jdhk jd Pamela";
var myName = "Pamela";
var hits = [];
for (var i=0; i<text.length; i++) {
    if (text[i]==="P") {
       for(var j=i; j<(myName.length + i); j++) {


your variable myName already contains your name, why push it into the hits array? I would get your name from the text variable. The purpose of your program is to get your name from the the text variable, so that is what i would push into your hits array


app returns this answer:
Oops, try again. Make sure you're pushing letters to the hits array!


Did you see my answer?


i don't understand what you try to say me


this line:


you try to push letters from your myName variable into your hits array, why? You want to get your name from the string stored in your text variable. That is the purpose of the program, not to get your name from the myName variable. (let aside the index error you get with trying to get your name from the myName variable)


ooo thanks a lot :wink:
you are right