Why was this accepted? Log it!



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++){
if(hits === 0){
    console.log("Your name wasn't found!");
    }else {


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)