6. Log It! Can't see what's wrong with this!


#1

This is my code:

/*jshint multistr:true */

text = "Hello there, How are \
you doing? My name is Simon.";

var myName = 'Simon';
var hits = [];

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

However, whenever I run it, I just keep getting errors!!!


#2

this line:

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

the semi-colon prevents the if/else statement from working properly, remove the semi-colon


#3

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