Will not print out name, just [ ]


#1

Hello,

It says good job and lets me go to the next lesson, but it is not printing out as expected. Here is my code:

/*jshint multistr:true */

var text = "Hey, how are you doing? My name is Zach.";
var myName = "Zach";
var hits = [];
for(var i = 0; i < text.length; i++){
if (text[i] === 'Z') {
for(var j = i; j < (myName.length+i); j++) {
hits.push('Zach');
hits[0];
}
}
}
if (hits.length = 0) {
console.log("Your name wasn't found!");
}
else {
console.log(hits);
}

When I do this, it just returns [ ] not my name. Help?


#2

Hi Zach,
Look at hits.push(). You push your whole name instead of text[j]. Hits probably contained 4 times (length of Zach) "Zach". But you probably set hits.length to 0 (in "if (hits.length = 0)" the = could make length zero. But I don't know that in Javascript. You should use '=== 0')
What do you want to do with the line "hits[0]"?
Hope this helps...