Your second "for" loop


#1


I really don't understand what I'm doing wrong. Help me.


https://www.codecademy.com/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.


var text = "mike mitiklf fsdlf dkfs sdf";
var myName = "Mitul";
var hits = [];

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


#2

@mitulexander,
Did you define a variable text ??
Could you provide us with the variable.....??


#3

My apologies, missed it in the copy, paste. I've updated it and it's in now.


#4

@mitulexander
Try it by using

var text = "mike mitiklf Mitul fsdlf dkfs sdf";

where your name is at least once mentioned.....


#5

Oh, should have used my brain there. Thank you!


#6

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