6.log it


#1

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


var text = "ashish how are you";
var myName = "ashish";
var hits =[];
for (var i = 0; i<=text.length; i++){
if(text[i] === "a"){
for(var j = i; j < myName.length + i; j++){
hits.push([j]);

       if(hits.length === 0){
           console.log("your name wasnt found");
           }
           else{
               console.log(hits);
               }
}
    }
}

i am not getting the required output instead some numbers are coming out
please let me know the mistake
also i didnt understand the myName.length +i part and the subsequent push() part


#2

Hi this line

hits.push([j]);

Inside push() you should put text[j] instead of [j] and

i didnt understand the myName.length +i part

You Can Read more about It here


#3

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