Something is wrong but it is still passing me. I would like to figure this out before I move on


#1

My name is Jesse by the way


#2

Try logging the value of hits outside of the loop.


#3

Still didn't work, but I might be doing something wrong.

var text= "helo heko Jesse kasfdj asiudhf\
ajdkshfandfiucdan Jesse asodhf a;lkdfjiafn jkasdf\
adsjfh ijsadiufh lkdsfn asduvbf Jesse";

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

#4

In that code snippet you're still logging the value of hits inside the loop.

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

See the else?


#5

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

Still doesn't work. I think I am totally missing something


#6

if (hits.length === 0) {


#7

Thank you. I love you.


#8

I missed that - however, do you see why that worked?


#9

I don't know for sure but probably there is a simple explanation because you aren't giving a value, like in the "var" statements but you want to know where "hits.length" is EQUAL to "0".


#10

Well actually = is the assignment operator, whereas === is one of JavaScript's comparison operators.

Can you draw a conclusion from that?