Code accepted but name is not printed


Hi, I've been stuck at this for almost 2 days since I'm lazying eversince the start of this array/loop exercise. I don't want to move forward without fully understanding these two elements.

So, I have compared my code with a lot here on the forum but cannot pinpoint my error. There was this advise to remove ( ; ) at some parts of the code and I did that but still the only thing printed on the console is []. Does this mean my name's characters were not pushed into the array?

Appreciate your help, please. Million thanks!

text="Blah blah blah blah blah Anj"
var myName="Anj";
var hits=[];
for (var i=0; i<text.length;i++) 
        for(var j=i; j < i + myName.length;j++)  
if (hits.length = 0) {
    console.log("Your name wasn't found");
else {


= is the assignment operator, you cannot use it to test length, it will not do that.

I suggest adding more prints to find out what's being done or not done. For example, you can add prints which show the array before and after pushing to it.


Stupid of me, I completely forgot about the === thing. It's working fine now. Thanks a lot!! :slight_smile:


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