Bug detected!


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-XEDZA/0/6?curriculum_id=506324b3a7dffd00020bf661#


If your name contains two or more letters which are same as the first letter (Example: SALSA). You will get an undesired output. There is nothing wrong with the code. It's just that the algorithm is inefficient.


/*jshint multistr:true */
var text = "blah blah SALSA blah blah SALSA blah blah \
 blah blah";

var myName = "SALSA";

var hits = [];

for(var i = 0; i < text.length; i++) {
    if(text[i] === myName[0]) {
        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

That is the whole point. The purpose of this project is to reveal the intricacies, not to go down those roads, just now. That is left to the user, even at the last lesson.

In this module we learned how to match a letter within a string, case-sensitive, and if we were watching, how to match any letter in a string, though the first is what we were after.

We learned how to parse a sub-string when a letter match is found in the outer loop. The concept of string length is drilled in, twice. We also learned how to array.push(item).

The point I'm making is that we need to see this for what is learned, not what is missing. The lesson does not need augmentation. It's a blip in the course path. We must let the user find a course of action to follow given the lesson contents. They benefit most from their own perseverance and due diligence.


#3

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