Second for loop in searching for name exercise


#1

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

It says "It looks like your second 'for' loop isn't pushing values to the hits array."
What's going wrong here?


/*jshint multistr:true */

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


#2

in your for loop:

 for (var j = i; j < text[i] + myName.length; j++)

why do you use text[i]? i will hold the index of the first letter of your name, so i would just use the index (in the variable i), not the related letter.


#3

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