6. Log it! can´t log my name


#1


6. Log it!


var text = "Hey, how are you \
doing, Tim? My name is Tim.";
var myName = "Tim";
var hits = [];

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

if(hits === myName)
{
    console.log(hits);    
}
else
{
    console.log("Your name wasn´t found!");    
}

Can someone tell me why he´s not printing my Name to the console? If I press "Save & Submit" he´s telling me "Way to go!" but i just get "Your name wasn´t found" outprinted. But if my two for-loops are correct then shouldn´t i get my Name printed to the console?


#2

look at your condition:

if(hits === myName)

hits is an array, myName is a string. This condition will be false. Please re-think this condition (read the instructions again)


#3

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