6. Log it! : console does not log expected answer


#1

Hi everybody,

Here is my code :

var text = "Hey, how are you \
doing? My name is Emily. \
— I'm fine, thanks ! My name is Etienne. \
— What ? \
— I said my name is Etienne. \
— Nice to meet you Etienne !";

var myName = "Etienne";

var hits = [];

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


if (hits.length===0){
    console.log("Your name wasn't found!");
    }
    else {
    console.log(hits);
}

The console prints [ 'E', 'm', 'i', 'l', 'y', '.', ' ', 'E', 't', 'i', 'e', 'n', 'n', 'e', 'E', 't', 'i', 'e', 'n', 'n', 'e', 'E', 't', 'i', 'e', 'n', 'n', 'e' ].

"Emily", "." and "," are not expected to be logged. Why do they appear ?

Thanks for your help !

Etienne


#2

Answering to myself...

Lesson 7 explains this is "normal"... I have to keep on coding to resolve this unsatisfactory console log.