Cannot Find The Issue


#1


https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661#

Oops, try again. There was a problem with your syntax.

var text = "Hey, how are you \ doing? My name is Jake.";
var myName = "Jake";
var hits = []

    for (var i = 0; i <= text.length; i++) {
     if (text[i] === 'J') {
        for (var j = i; j < (i + myName.length; j++)
    { hits.push(text[j])} 
    }
    }
    
    console.log (hits);


#2

HI this line

for (var j = i; j < (i + myName.length; j++)

this part

 j < (i + myName.length;

you didn't close the )


#3

You need to close off the bracket at j < (i + myName.length); plus semi colon after closing bracket for hits.push([j]) leaving out the variable designator text as you can call it dynamically. Here is my solution:

`//jshint multistr:true;
var text = "I love life and John John Groovy man!";
var myName = "John";
var hits = [""]; //must be letters (chars) so "" types array as string

for(var i = 0; i < text.length; i++) {
if(text[i] === myName[0]) {
for(var j = i; j < myName.length + i; j++) {
hits.push([j]);
}
}
}
if(hits.length === 0) {
console.log("Name not found...");
}
else {
console.log("Result is "+hits.length);
}
`


#4

data type the array as string var hits = [""];


#5

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