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.

I am so confused the instructions aren't very clear and I don't understand.

/*jshint multistr:true */
var text = "Hello Grace how are you today? What are you doing Grace? What are you eating Grace?";
var myName = "Grace";
var hits = [];
for (var i = 0; i < text.length; i += 1) {
    console.log(i);
    if (text[i] === "G") {
    for (i = 0; i < text.length; i++) {
    if (text[i] === "G") {
    for (j = i; j < i + myName.length; j++) {
        hits.push(text[j]);
    }
    }
}
}
}


#2

You should have only two for loops, you have three remove the second duplicate one,

And You only require threee closing brackets after this line,hits.push(text[j])


#3

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