In the editor my whole name is printed, rather than individual letters. what might be wrong with my code?


#1
var text = "Cristian Cristian";
var myName = "Cristian";
var hits = [];
for(i = 0; i < text.length; i++){
    if(text[i] === 'C') {
        for(j = i; j < i + myName.length; j++){
            hits.push(i);
            hits[i];
        }
    }
}
if(hits.length === 0){
    console.log("Your name wasn't found!");
}
else{
    console.log(hits);
}

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

should read,

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

so that one letter at a time is appended to the hits array in the inner loop.