Why are letters not being pushed ot the hits array


#1

6 Search Text for Your Name

receiving this error message "Oops, try again. Make sure you're pushing letters to the hits array!" and console printing out "[ 6 ]
[ 6, 7 ]
[ 6, 7, 8 ]
[ 6, 7, 8, 9 ]
[ 6, 7, 8, 9, 10 ]
[ 6, 7, 8, 9, 10, 11 ]
[ 6, 7, 8, 9, 10, 11, 58 ]
[ 6, 7, 8, 9, 10, 11, 58, 59 ]
[ 6, 7, 8, 9, 10, 11, 58, 59, 60 ]
[ 6, 7, 8, 9, 10, 11, 58, 59, 60, 61 ]
[ 6, 7, 8, 9, 10, 11, 58, 59, 60, 61, 62 ]
[ 6, 7, 8, 9, 10, 11, 58, 59, 60, 61, 62, 63 ]


var text = "Hello Gillie, how are you today? Have you been on holiday Gillie?";

var myName = "Gillie";

var hits = [];

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


#2

j are just numbers? They do however match the indexes of your name in text. Use j as index to retrieve values from text string


#3

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