Hi please help me with this code its not working


#1


/*jshint multistr:true */
var text = "My name is shreyas \ and i live shreyas in India";
var myName = "shreyas";
var hits = [];


for( i = 0 ; i < text.length ; i++){
    if(text[i] === "s"){
        for(j = i; j < i + myName.length ; j++){
        
        hits.push(text[i])
        
        }
    }
}
if(hits === 0){
    console.log("Your name wasn't found!");
  
}else{
    console.log(hits);
}


#2

you push i into your hits array, this should be j, since you use the second for loop to loop over your name


#3

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