The Search Text for Your Name exercise is confusing because


It's confusing because it does not specify in the beggining of making this program that it does not search for the entire word. It will only find the first letter of your name: myName[0], puts that and the next letters based on however many letters are in your name: myName.length into the empty array hits = [ ]

So if you did this:

var text = "amos andy amos";
var myName = "amos";
var hits = [];
for(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 {

You would get that:

[ 'a', 'm', 'o', 's', 'a', 'n', 'd', 'y', 'a', 'm', 'o', 's' ]

even though the you were searching for amos and not andy!!!


Yes. They inform about this in the last exercise, which is a total stupidity.

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:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.