Search for name Log It!


#1

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

Just keep getting this below
[ ‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’,
‘a’ ]



/*jshint multistr:true */

var text = "This is a string of text andrew these are words for the string so andrew may figure out to find specific names like andrew";
var myName = "andrew";
var hits = [];

for (i = 0; i < text.length; i++) {
    if(text[i] === 'a') {
        for (var j = i; j < (i + myName.length); j++) {
            hits.push(text[i]);
        }
    }
}
if (hits.length === 0) {
    console.log("your name was not found");
}
else {
    console.log(hits);
}



#2

why push text[i] into the array? we use the second loop to get the name, so you should push text[j] into the array


#3

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