Code Accepted but "Name Not Found"


#1



It was accepted as correct but when I try to search my name, it says Your Name Wasnt Found! Even though it is there.


/*jshint multistr:true */

var text = "leeeedleleeedleleeeeedleleeeeedleeeeedleeeeeedgreergreerrrrr";
var myName =  "Greer";
var hits = [];

for (i = 0; i < text.length; i++) {
if (text[i] === 'G') {
     for (var j = i; (i + myName.length); j++) {
         hits.push( text[j] );
     }
}
}
if(hits.length == 0) {
    console.log("Your name wasn't found!") 
    } else {
    console.log (hits) }


#2

You try to find 'G' but var text doesn't have 'G'. So, if (text[i] === 'G') returns false.
Put GreerGreerrrrr in your string:

var text = "leeeedleleeedleleeeeedleleeeeedleeeeedleeeeeedGreerGreerrrrr";

As you can see, 'g' != 'G'.


#3

This fixed it, thanks


#4

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