Wrong output


#1


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


Giving wrong output it should print hassan but it prints all letters equal to length of "hassan" if it founds an "h"


 text="this is ali and he is my friend hassan is my name and my name is hassan also";
var myName="hassan";
var hits=[];
for (var i=0;i<text.length;i++){
    if(text[i]==="h"){
        for(var j=i;j<(i+myName.length);j++){
            hits.push(text[j]);
            }
        }
    }
    if(hits.length==0){
        console.log("Your name wasn't found");
        }
        else{
            console.log(hits);
            }


#2

Quote from the last exercise:

Now, as we mentioned, this system isn't perfect. For instance, if the paragraph contains both "Eric" and "Eddie", we'll see this in our hits array:
['E','r','i','c','E','d','d','i','e'];

:slight_smile:


#3

agree with you.in ur case it will contain ['E','r','i','c','e','d','d','i']


#4

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