Your second "for" loop


#1


I don't know whats wrong with this code can someone help me, please.

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

Oops, try again. There was a problem with your syntax.
SyntaxError: Unexpected token


var text = "Aaron likes pi. Aaron also like cake. Aaron likes food in general.";
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

It would seem that all your } are unnecessary alteast according to my work on this lesson. Also a ; is needed after [] Other than that your answer is the same as mine with a different name


#3

for (var j = i; j < (i + myName.length; j++) // missed a ) after myName.length

and

 hits.push((text[j]);  //here remove a ( you added a extra

#4

wow that worked thank you


#5

Thank you for the help as well I would have never noticed that


#6

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