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


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
/*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]);

    }
    
}

};

<In what way does your code behave incorrectly? Include ALL error messages.>
My code DOES works I just want a better understanding of the hits [ ] array. Thank you.

```

Replace this line with your code.

<do not remove the three backticks above>

#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<i+myName.length; x++) {
hits.push(text);

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<i+myName.length; x++) {
hits.push(text);