The code as some issues


#1

Hello,
the code as it shown on page 1 - works but only if we have the word that starts at the right letter and the same letters we need.
but if there will be Epic - instead of Eric it will push it as well.
and you use myName only for the length - it's not actually comparing between the word in the text and this var.

Thanks,
Nat.


#2

@digitalninja42004,

// text that contains all the characters of my name
 text = "Honestly?"+
       " My understanding of JavaScript"+
       " is elementary as best"+
       "Holden is staying at "+
       "the Holiday-Inn.";

// declare a variable for my name
 var myName = "Holder";

//declare an empty array to hold the result of the for loop
 var hits = [];

// Look for "H" in text
 for(var i = 0; i < text.length; i++) {
   if (text[i] === myName[0]) {
    // add matching characters to new array
    var textToCapture = "";
    for(var j = i; j < (myName.length + i); j++) {
         textToCapture += text[j];
    }
    hits.push(textToCapture);
   }
 }

// log results for search to the console
 if (hits.length === 0) {
   console.log("Your name wasn't found!");
 } else {
   console.log(hits);
 }

You could expand the function
by checking if the testToCapture equals to myName......