Your Second "for" Loop - says code is correct, but I don't think it is


#1



My code outputs "10" to the console. Shouldn't it output my name? What am I doing wrong?


/*jshint multistr:true */
var text = "The people of St. Louis love sports joy and sporting events like James \
            the Blues are a popular team that James loves a lot";
var myName = "James";
var hits = [];

for (i = 0; i < text.length; i++) {
    if (text[i] === 'J') {
        for (k = i; k < (i + myName.length); k++) {
            hits.push(text[i]);
        }    
    }
}


#2

no, this code only pushes the letters into your hits array, logging this to the console is what you will work on in the next lesson


#3

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