6/7 Unecpected token else


#1

This is my code

/*jshint multistr:true */
var text = "Hey, how are you \
doing Jen? My name is John.";
var myName = "John";
var hits = [];
for(var i = 0; i < text.length; i++) {
if (text[i] === myName[0]) 
for(var j = i; j < (myName.length + i); j++) {
hits.push(text[j]);
}
}
if (hits.length == 0) {
    console.log("Your name wasn't found!");
};
else {
    console.log(hits);
};

Error code: SyntaxError: Unexpected token else

HELP


#2
if (hits.length == 0) {
console.log("Your name wasn't found!");
};
else {
    console.log(hits);
};

There should not be a semicolon after your if statement, if you're making an else statement too.


#3

if (hits.length == 0) {
console.log("Your name wasn't found!");
}
else {
console.log(hits);
};


#4

This is how your code shoud look like:

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