Your second "for" loop


Same as many on the forums, this question seems to not like my answer.

var text = "For I know the plans I have for you, declares Marco, plans to prosper you and not to harm you, plans to give you hope and a future.";
var myName = "Marco";
var hits = [];

for (var i = 0; i < text.length; i += 1){
    if (text[0] === 'M'){
        for (var j = i; j < i + myName.length; j += 1){

If anyone can give some clarification, that would be great.


The problem is here:

if (text[0] === 'M')

You see what is wrong? Each time, you compare your first character of the string stored in text (that is an F) to see if it equal to M, well, it is not not. You use the first for loop to loop over the text, you should use that for comparison:

if(text[i] === 'M')

Make sense?


Yep, makes perfect sence. Cheers for the explanation :ok_hand: