Log it! (Code passes but doesnt log name)


#1

As the title implies, my code DOES pass, but it doesn't log and i cant seem to find the error. Could someone help me out?

/*jshint multistr:true */
var text = "Hey man, how are you doing? My name is Beau - i don't know what made my parents pick Beau as a name but i think Beau is pretty Beau :)";
var myName = "Beau";
var hits = [];

for (var i = 0; i < text.length; i++){
if(text[i] === "B"){
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);
}


#2

@beautje,
In your IF condition you will have to use a comparison operator ===
like

hits.length === 0

instead of using the assignment operator =

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators


#3

Thank you very much! Atleast i was close! ;D