Stuck, it's letting my pass although it says undefined in the console


#1

Hey guys, I'm stuck on the Search text for your name lesson, 6: Log it. It lets me pass the lesson, although I get undefined as a result in the console. Any help?

var text = "david afsdgskdgjbs david gnsdk f fjdnjg dav dfjslnfns david";
var myName = "david";
var hits = [];
for(var i = 0; i < text.length; i++) {
    if(text[i] === 'd') {
        for(j = i; j < i + myName.length; j++){
            hits.push(text[j]);
        }
    }
}
if(hits === 0) {
    console.log("Your name wasn't found!")
}
else {
    console.log("Your name was found!")
}
console.log(text[j])


#2

i would write your name with uppercase letter, otherwise it will find all letters d

You need to log hits (the array) to the console, that contains your name


#3

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