I've no idea what is going on


#1

What is in the interpreter:

[ '.' ]

This is what I coded:

/*jshint multistr:true */
var text = "Hey, how are you \
doing? My name is Fate.";
var myName = "Fate";
var hits = [];
for (var i=0; i<text.length; i++) {
    if (text[i] === "F") {
        for (var j=i; j<(myName.length+i); j++) {
        };
    };
};
hits.push(text[j]);
console.log(hits);

And this is what I do not understand:

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

Can some kind soul explain to me what is "myName.length+i" and I still don't understand the ".push" function even after reading the explanation provided...


Your second "for" loop 5/7
#2

This particular exercise made my brain hurt a bit as well before. Let me give a shot at explaining it to you.

By the way, you final code should look like this one below:

var text = "Hey, how are you \
doing? My name is Fate.";
var myName = "Fate";
var hits = [];
for (var i=0; i<text.length; i++) {
    if (text[i] === "F") {
        for (var j=i; j<(myName.length+i); j++) {
            hits.push(text[j]);
        };
    };
};
console.log(hits);

With the first for loop you are iterating over every character in your text variable and checking if it is equal to string "F". Once if returns true after finding an equal character, second for loop comes into action.

First of all, it tells where "F" was found and assigns that location to variable j.
For example lets say "F" was 10th character in variable text.

Then it evaluates if the condition is true. Which is true.

j < (myName.length + i);  // Assuming "F" is 10th char:  10 < (4 + 10);

After evaluating to true, this for loop will run 4 times (with j++ increments) and will populate hits array with characters by using push() method on it.

:cat:

Hope it's not too confusing and will help you to understand why it was done in such way.