Second "for" loop, help?


#1


Hey all, I keep getting an error on my code, but I've looked back at the original code that worked, and done everything similarly, and I still can't figure it out. Anyone care to take a crack at it and let me know what's wrong with my code so it will work?


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


This is the error code I'm getting:
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.


/*jshint multistr:true */
var text = " I like people named Lana but only on the days of the week that end in Y. Other times I can't stand people like that ever. Especially, Lana, Emily, Kristin, Rachel, Beatrix Kiddo, and other people. Blah blah blah blah blah blah blah.";

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

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


#2

Add prints to make it let you know what it does so you can see where it deviates from what you want it to do


#3

Thanks for responding so quickly! I'm not sure what you mean, though?


#4

It's supposed to carry out some actions, isn't it? Make it print out what those are, so that you can compare what it says it does with what you want it to do

If it does something wrong but you don't know what it's doing wrong, then you'll need to observe what it does.


#5

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