Second For Loop


#1

Hi everyone. I am stuck on my second for loop. I have tried changing a few things based on responses i've seen with other people having the same issue, and I can't seem to figure out what I have wrong. This is my error message:
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.

Thanks in advance!

text = "blah","blah","blah","Josh", "Josh", "blah";

var myName = "Josh";
var hits = [];

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

#2

text = "blah, blah, blah, Josh, Josh, blah";

#3

Ok. I think what @denys.matsevych was trying to say is that you need a var for your text for it to actually be a text variable. Second

Your for loop comes out false therefore you need to change it to make it true. I would suggest a flip of <.
Third

This does not need to be in () . That should fix all your problems.


#4

Removing the quotation marks fixed it immediately. Thank you!


#5

Thank you for your feedback! I got it squared away and it worked great.


#6

Glad to hear that! It is always great when you can figure it out on your own! :smiley:


#7

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

@bibleman13,

Your for loop comes out false therefore you need to change it to make it true

I didn't catch what's wrong with for loop?

This does not need to be in ()

But why??


#8

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