Doesnt just show my name, shows every letter with a captial A


#1



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


I did add another way of displaying the name, but you can just ignore that.
My problem is that it shows every word that starts with a capital A instead of just my name, Alex.


/*jshint multistr:true */
var num = [];
var text = "code code code Alex code code Alex code code And code code Also code code Alex code";
var myName = "Alex";
var hits = [];

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

console.log(hits);
console.log(num);

for(i = 0; i < num.length; i++) {
    console.log(text[num[i]]);
}


#2

The exercise relies on the name being the only capitalized letter, but if you don't want this, you can also check the last letter (length -1 == "x"), just add another if statement inside the current if statement, or if you are familiar with the && use the and operator instead


#3

Ah.. why couldnt i think of that ;-; haha thanks, thats a great idea! :slight_smile: