I need help in "Your second for loop" quick!


#1

This code is really tough for me and I have tried everything and I don't know what to do

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

When I run my code, it won't work. It says, "Oops, try again. 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." I have made sure that my name appears in the text variable, but nothing seems to work. I have tried everything, please help.:disappointed:

/*jshint multistr:true */
var text = "Dim sum with Ally";
var myName = "Ally";
var hits = [];
for(var i = 0; i < myName.length; i++){
if (text[0] === "A") {
  for(var j = i; j <i + myName.length; i++){
  hits.push(myName[j]);
  }
}
}


#2

What about changing your

in the 2nd FOR-loop
into
j++


#3

That one didn't work, but thanks for trying to help!


#4

You also try to take a character from =myName= should that be =text= ???
myName[j]


#5

Thank you, that helped me solve my code!:grin:


#6

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