I completed the syntax, but i dont get what the hits[ ] variable actually did


#1



/*jshint multistr:true */
var text= "Hey hows your day going so far chris?";
var myName="chris";
var hits=[];

for (var i=0; i<=text.length; i++){
if(text[i]==="c"){
for (var j=i; j<=[i]+myName.length; j++){
hits.push(text[j]);

    }

}

};


My code DOES works I just want a better understanding of the hits [ ] array. Thank you.


Replace this line with your code.


#2

Also, I have added and if statement to the end of my syntax....

if(hits.length===0){
console.log("Your name wasn't found!");
}
else{
console.log(hits);
}
After I hit save and submit the console does log my name but it also logs a long list of 'undefined' strings...did this happen to everyone or is it just me? please give me some feedback. Thank you as always!


#3

for(x=i; x hits.push(text[x]);

make sure there is no [i] on the second for loop.
The hits[] form what I understood is just declaring a empty array that you will be adding values into which you did using the ,push method.

hope this helps.


#4

for(x=i; x hits.push(text[x]);