Completed Second for loop however I do not know how


#1

Ive recently completed the fifth step in "search text for your name". My code gives an answer of '12' though. Ive changed what var i push and also changed things in the hit box. its odd because it will either not work or still return '12'. Below is my code any guidance would be greatly appreciated. Thank you for your time.

/*jshint multistr:true */
var text = "my name is steven.";
var myName = "steven";
var hits = [];
for (var i = 0; i < text.length; i++) {
if (text[i] === 's') {
for (var j = i; j < myName.length + i; j++) {
hits.push(text[j]);
}
}
};


#2

Your code looks good, but instead of checking if text[i] === 's', check if text[i] === myName[0]

Then the code will work for any name in the variable. The 12 answer you're getting is likely because you referenced your name twice - S T E V E N, 6 letters pushed into hits twice for 12 total pushes.


#3

Unfortunately my code still returns "12" after making those changes. Though what you said to change does make sense to me.

var text = "my name is steven.";
var myName = "steven";
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,0]);
}
}
};