Your second "for" loop


#1

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

Second for loop isn't pushing values


var text="Hey yash how are you/ party?";
var myName="yash";
var hits=[];
for(var i=0; i<text.length; i+=1){
    if(text[i]=== 'y'){
        
        for(var j=i;j< (i+myName.length); j++){
            
            myName=[];
            myName.push("yash");
            myName[0]=("y");
        }  
        }
        
    }


#2

Try replacing the contents of the for loop with sometime to push j to the array hits. hits.push(text[j])


#3

j contains the indexes of your name stored in text, so you can use text[j] to get the letters. That is what you should push into your hits array. (you created the array for this purpose)


#4

Can you please edit the code and show me?


#5

can you show an updated version of your code? So we can help you further


#6

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