5/7 Help!?


#1

/*jshint multistr:true */
var text = "Shae Shae Shae" ;
var myName = "Shae";
var hits = [];

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

console.log(hits);

The error with that is:

Oops, try again. It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable.

Also if someone could explain .push to me in a different way than them, I would really appreciate it. It isn't making any sense yet.


#2

@shaekelly,

*jshint multistr:true */
var text = "Shae Shae Shae" ;
var myName = "Shae";
var hits = [];

for (var i = 0; i< text.length; i++) {
    if (text[i] === myName[0]) {
        found = ""; 
        for(var j = i; j < i + myName.length; j++); 
            hits.push( text[ j ] );
            found += text[j]
        }
        if (found===myName){
             //do something of your own.. but NOT this hits.push(found);
        }
    }
}
console.log(hits);