Exercises Three through Six are not working


#1

var text = "Hey, how are you doing? My name is Taylor.";
var myName = "Taylor";
var hits = ["Taylor"];
for ( var i = 0; i < text.length; i++){
if text[i] === 'T') {
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);
}

I have completed the exercises to the specifications of the instructions and they all resulted in "syntax error", I need assistance in order to move forward onto the next section of this course.


#2

I am slowly correcting the errors of my code.


#3

on this line

if text[i] === 'T') {

you are missing an opening bracket

if (text[i] === 'T') {// you were missing an opening bracket here

also one more thing your hits array must be empty initially , it cannot have anything in it

var hits = ["Taylor"]; //should rather be var hits = [];

after you have corrected your current code and tested it you can take a look at this post to get an idea how to improve the push to hits
click here to post