Search for your name


#1



Hi guys. I'm stuck on this exercise, especislly the push() function. I'd appreciate the help

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


/*jshint multistr:true */
var text= "You might be a big fish\
 in a little pond\
doesnt mean you've won";
var myName= "Aisha";
var hits= [];
for (var i=0; i < text.length; i++) {
if(text[i] === 'A') {
    for (var j=i; j < i+myName.length; i++ ) {
    hits.push()
    }
    }
}


#2

why in your second for loop do you have i++? i would increase j, since that is going to loop over your name.

well, j only contains the indexes of your name. but we can use j to access the letters at this index in your text variable using text[j], which is what i would use inside your push()


#3

/*jshint multistr:true */
var text= "You might be a big fish\
in a little pond\
doesnt mean you've won";
var myName= "Aisha";
var hits= [];
for (var i=0; i < text.length; i++) {
if(text[i] === 'A') {
for (var j=i; j < i+myName.length; j++ ) {
hits.push(text[j])
}
}
}

Like this? @stetim94


#4

yea, like that. Does it work?


#5

It didn't work @stetim94


#6

i forgot that. In the string stored in your text variable, Aisha isn't in the string, which means nothing is found, so nothing is pushed into the hits array. Add your name to the string stored in the text variable


#7

/*jshint multistr:true */
var text= "You might be a big fish\
in a little pond\
doesnt mean you've won";
var myName= "Aisha";
var hits= [];
for (var i=0; i < text.length; i++) {
if(text[i] === "Aisha") {
for (var j=i; j < i+myName.length; j++ ) {
hits.push(text[j])
}
}
}

Like this? @stetim94


#8

what did you do? Your if statement was fine, i was talking about the declaration of the text variable on line1:

var text = "you have some string here, to which you need to add your name"

#9

/*jshint multistr:true */
var text= "Hi\
my name\
is Aisha";
var myName= "Aisha";
var hits= [];
for (var i=0; i < text.length; i++) {
if(text[i] === 'A') {
for (var j=i; j < i+myName.length; j++ ) {
hits.push(text[j])
}
}
}

Like this @stetim94


#10

why not simply run it? If it works, the code is good. It works for me


#11

It worked. Thank you @stetim94