Second for loop in searching for name exercise


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++) {


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.


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