Your second "for" loop


#1

I'm joining the club for this one. I'm not sure what I've done wrong. Any help would be appreciated.

I'm getting the "It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable." error.

Thanks

/*jshint multistr:true */

var text = ("This is Aaron a long string of text so Aaron the program can look for my Aaron name in it.");

var myName = ("Aaron");

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]);
        }
    }
}


#2

for ( var i = 0; i < text.length; i++); // remove ;

and

( var j = i; j < (i + myName.length); j++); //same here

#3

Thanks. That did it.


#4

Got mistake: SyntaxError: Unexpected token )

I don't understand what it means

Help please!

/*jshint multistr:true */

var text = "Hey, how are you \
doing? My name is Emily.";
var myName = "Emily";
var hits = [];

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


#5

Try refreshing the browser.


#6

Why does "i + myName.length" have to be in parenthesis?

Can anyone explain?


#7

it depends on you.it's not compulsory :slight_smile:


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.