JavaScript Unit 3 Lesson 6: Your second "for" loop - PLEASE EXPLAIN


#1


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

Thank you in advance if you take the time to read this and reply to a beginner. :slight_smile:

I am SOOO confused at this... Please can someone explain to me exactly what my codes does line by line.
This unit didn't explain very well so I had to look on the forums for the answer... but I just don't understand it. So for me this unit has been pointless. :frowning:
I really love learning but I don't want to move on with the course until I understand what the code does.

Thank you!


/*jshint multistr:true */

var text  = "test test test test Rhys test test test test \
            test test test test test test test test Rhys";
var myName ="Rhys";
var hits = [];

for (var i = 0; i < text.length; i++) {
if (text[i] === myName[0])
    {
     for (var j = i; j < myName.length + i; j++) {
         hits.push(text[j]);
        }
     }
};

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


#2

I wrote an extensive explanation here and another one here, and i am sure there are more, the problem is that such explanations are very time consuming to write. Please read them, and ask if you have any specific questions afterwards