<6. Log it> some bug maybe?


#1



/*jshint multistr:true */

var text = "Hey do you know who I am? My name is Briandhika. In Nihongo, it pronounce as Watashi wa Briandhika desu. Of course, desu pronounce more like desh than the real desu. Okay, enough with this chit-chat, program it so Briandhika can get out from this sentence and shine. Briandhika.";

var myName = "Briandhika";

var hits = [];

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

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

First, I passed this Lesson with these codes, but later I think about it again and I found some errors.
I try to change every "Briandhika" words in var text to Briandqrqhika so the program should find it not right. But the compiler works and say "Way to go! Start Next Lesson".

The result screen shows ['B','r','i','a','n','d','B','r','i', ..... and so on instead of Your name wasn't found!.

I think this code is not quite good.
So, why can I pass with this code?


#2

Read the instructions. The title is a misnomer, but it will find your name, if it's there; otherwise, it will find the first letter in your name followed by as many characters as follow the first letter in your name.