Code does not work


#1

I used the code they provided and the code I wrote with the text I created. I then switched out the search letter to "T" and myName to "Tom".

My understanding is that it will return every time your name is entered. It returns every word that starts with To that is 3 letters long. See image below

var text = "hey this is strange Tom Tor Toa Toq Top Toc Toz Tol Tommy said that we wish we could all come together and try this out this time. I am not sure Tom would like to know about it. They said that this was frank smith rubber phone works policy. effectice Tom goverment.";
var myName = "Tom";
var hits = [];
for (var i = 0; i< text.length; i++){
    if(text[i] === "T"){
   
   
   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

Specifically, it will check the text for the first letter of your name, then push (add) the number of characters equal to your name's length to an array. By inspecting the array, you'll be able to see if your name was mentioned!

This loop will make sure each character of your name gets pushed to the final array. The if statement says: "If we find the first letter of the name, start the second for loop!" This loop says: "I'm going to add characters to the array until I hit the length of the user's name." So if your name is 11 letters long, your loop should add 11 characters to hits if it ever sees the first letter of myName in text.

You've now got the engine of your search program running. It will:

Loop through the array,

Compare each letter to the first letter of your name, and if it sees that letter:

It will push that letter and all the letters that follow it to an array, stopping when the number of letters it pushes are equal to the number of letters in your name.

Now, as we mentioned, this system isn't perfect. For instance, if the paragraph contains both "Eric" and "Eddie", we'll see this in our hits array:

    ['E','r','i','c','E','d','d','i'] // note correction

The code as entered in the OP works as expected and as described. I don't see a problem here.


#3

which one is this for axactley