Why is it not working?


#1

 the error says:ReferenceError: Can't find variable: hits

var text = "hey how are you \
doing? my name is William.";
var myName = "William";

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

Take a careful look at the error message. It's saying that some variable doesn't exist.
Should it exist? Where and when should it have been created?


#3

take a closer look on the declared variables. the error says, the variable "hits" was not declared.


#4

i'm not sure where it should be. actually it doesn't matter i've found it thanks so much for the help :smile: :slight_smile:


#5

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