5. Your second "for" loop. Been stuck here forever


#1

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

"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've tried everything I can think of, with and without semicolons in various places. What's happening? This looks correct to me.


var text = "blah, blah, blah, blah, Jon, blah, blah, \
blah, blah, blah, blah, blah, blah, Jon, blah, \
blah, blah, blah, blah, blah, blah, blah, blah, Jon";

var myName = "Jon";

var hits = [];

for(i = 0; i > text.length; i++) {
    if(text[i] === 'J') {
        for(j = i; j < myName.length + i; j++) {
            hits.push(text[i])
        }
    }
}
console.log(hits)


#2

Use the inner loop iterator variable, j in the index.

hits.push(text[j]);

#3
for(i = 0; i > text.length; i++) {
    if(text[i] === 'J') {
        for(j = i; j < myName.length + i; j++) {
            hits.push(text[j]);

I still get the same error message. :frowning:


#4

Change the direction from greater than to less than.

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

#5

That worked.
0_0
Thank you. Coding is hard.


#6

It does get easier, though. The concepts are hard to grasp when we are still struggling with syntax, but work on the concepts and the syntax will fall into place.


#8

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