Can some Explain why its: j < (myName.length + i)?


#1

/*jshint multistr:true */
var text = " Addfsdf sdfsd ggsdf bbfdn gnfd n mmasvms smfms \
martijn adsljkdsafa martijn sdjklfa sdfjl asdjf";
var myName = "mason";
var hits = [];
for (var i = 0; i < text.length; i++){
if (text[i] === myName[0]){
for (var j = i ; j < (myName.length + i); j++) {
hits.push(text[j]);
}
}
}
if(hits.length === 0){
console.log("Your name wasn't found!");
}
else {
console.log(hits);
}

Can some Explain to my why its: j < (myName.length + i) instead of just: j < myName.length


#2

I already found out why, if anyone else needs the explanation here it is:

Lets say var i = 33 and i < text.length then it becomes i = 34. No i = 34 the program checks if the first postion in myName === m.
If myName === m then j = i, in numbers j = 34, meaning that if we do not add this total amount to myName.length the result will never be true. This is because j = 34 so its impossible that j < myName.length (which is 5), for this reason we add i (34) to myName.length - evening out the value that is set for j.


#3

Still do not understand. Can someone provide a play-by-play explanation?
I am still lost from myName === m, why then is j = i?