Why was this accepted? Log it!


#1


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


This code was accepted but the output is not right, it outputs the whole text until it reaches my name and stops.
not sure what is wrong.
this is the code

/*jshint multistr:true */

var text ="hello, my Name is Hassan, and i live in agadir city\
and i love it, Agadir has very nice beaches and you can find ";

var myName ="Hassan" ;

var hits =[]; 

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

#2

it is because your second for loop is wrong, it should be:

var j  = i;

not var j = 1, you want it to loop from the start of your name (i, which contains the index of your name, thanks to the if statement) till the end (i+myName.length)