Search Text For Your Name 6/7


I have read just about everything I can about this and it just doesn't make any sense to me at all. Nothing about it, top to bottom, seems to click with me so I have decided to run through it as many times as it takes to get it to stick, but after my second attempt I am getting correct code, but this is all that gets pushed to the array [ ' ', ' ' ]. Before I had it correctly displaying my name, but I just wasn't getting it so I started over. Here's the code:

/*jshint multistr:true */
var text = "Andy is a good guy who does some things that are good. \ Andy is pretty good, eh?";
var myName = "Andy";
var hits = [];

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

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

Any comments on what exactly each part of this code does and why I am getting the result I am getting would be greatly appreciated. Thanks in advance.

  1. var text is missing " at the end.
  2. Your if statement in the first for loop, try to place the second for loop in the matching scope of { }, so I will fix it as,
    if (condition)
    { for (statements)
    { hits.push(text[j]);
    } // 2nd for loop ends
    } //if scope ends here


Remove ; at the end of: for(var j = i; j < (i + myName.length); j++)