Need a correction


#1

var text = "hello hello hello hello hello Kanaya hello hello hello Kanaya hello hello Kanaya hello hello";
var myName = "Kanaya"
var hits =[];

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

The system told that the code is right but.. the output in the console just "[ ]"

What's wrong?
can you guys give me a correction..


#2

This is not a comparison. You should rethink it :slight_smile:


#3

Problem is here:

if(hits.length=0) { ... }

You used wrong operator, try == or === instead.
= - assignment operator
== - equal to
=== - equal value and equal type


#4

alright i got it... thank you :smiley:


#5

yes i did lol thank you


#6

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