Help me understand this code!


#1

Hey all,

I finished this course, and I figured out how to write the code, but I end up not understanding some parts of the second loop. Here is my code:
/*jshint multistr:true */

var text= "blah blah blather Jeff bleh bluh Jeff lol";
var myName= "Jeff"; 
var hits= [];

for(i = 0; i < text.length; i++){
    if(text[i] === "J"){
        for(var j = i; j < (myName.length + i); j++){
            hits.push(text[j]); //right above and the if statement
        }
    }
}

if(hits === 0){
    console.log("Your name wasn't found!");
}
else{
    console.log(hits);
}

It would be appreciated if you could help me out, because I've tried to figure it out, but I can't.

Thanks!


#2

@orvvlatter,

Have a read
https://www.codecademy.com/forum_questions/548f6fad937676f0b300010a#answer-548ff7899376767d16000c59


#3

Thanks for giving me the link! I experimented with the code a little, and now I can understand the loop.