Done Correctly... still don't get it!


#1



Hey there,
So, this code is correct!!! YAY! But, I am still confused as to how I did it. It's like the pieces are all there, I just can't make sense of them. Can anyone explain how I did this to me. I understand declaring variables, I understand making arrays, I guess I get confused right after that! Help explain, if you can!!!


var text = "Hey there. I am Celeste. One of the most Celeste people that have ever been Celeste. Vote for me, Celeste!";
var myName = "Celeste" 
var hits = [] 
for(var i =0; i< text.length; i++) {
    if (text[i] === 'C') {
       for(var x = i; x <= (myName.length + i); x++) {
            hits.push(text[x])
        } 
    }
};
if ( hits.length ===0) {
    console.log("Your name wasn't found!");
} else {
    console.log(hits);
}


#2

@mrsmedicine
Here a story using left & right index-finger
https://discuss.codecademy.com/t/i-passed-this-but-i-just-need-someone-to-explain-the-second-for-loop/30895/2?u=leonhard.wettengmx.n


#3

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