Search Text For Your Name


#1


My if/else statement is not working and keeps returning "unexpected token ) "


/*jshint multistr:true */
var text = "Hey how are you Alex?\
Do you want to see a movie Alex?";
var myName = "Alex"
var hits = [];
for (var i = 0; i < text.length; i++){
 if (text[i] === 'A'){
 for (var j = i; j < (i + myName.length); j++){
     hits.push(text[j]);
 }
 }
} 
console.log(hits);

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


#2

Hi you get this error becuase of this line

if(/*hits.length is 0*/)

you should do what the comment inside the if condition says.. with the comparison between hits.lenght and 0


#3

Thanks yeah i just figured that out. It was those lovely little ** that kept the whole thing from working.


#4

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