Help on 5


#1

What is wrong with my code? I keep getting a numerical output instead of words/letters.

/*jshint multistr:true */
var text = "My name is jack and jack is a tight name \
you right jack you right jack you right jack";
var myName = "jack"
var hits = [ , , , ];
for(var i = 0; i < text.length; i++) {
if (text[i] === "j"); {
for (var j = i; j < (i + myName.length); j++) {
hits.push(text[j]);
}
}
}


#2

Hi @jackrosa183

You have to do an empty array, nothing inside.
Delete semicolon after "if" condition (line 6).
Don't forget to call you "hits" variable to see the result

var text = "My name is jack and jack is a tight name \
you right jack you right jack you right jack";
var myName = "jack";
var hits = [];

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

console.log(hits);

Hold on :wink:


#3

Thanks a ton it worked!