5. Your second "for" loop


#1



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="This is\
a very long long\
long line of text!";
var myName="Constance";
var hits=[];

for (var i=0;i<text.length;i++){
    
    if (text[i] === "C"){

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

#2

`
var text="This is\
a very long long\
long line of text!";
var myName="Constance";
var hits=[];

for (var i=0;i<text.length;i++){

if (text[i] === "C"){

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

// missing }

And i wanna know from you why you search for a C in an text where no C is?
How you wanna push in your hits array if there is nothing to push?


#3

It works now! I changed the text. Thank you!


#4

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