#5 Started to get lost here?



Oops, try again. Careful: your second 'for' loop should stop when it reaches its current point in the string + myName.length.

 /*jshint multistr:true */
var text = "Some text involved.";
var myName = "Devon";
var hits =[] ;

for (var i = 0;  i < text.length; i++ ){
    if (text[i] === 'D'){
for (var j = i; j < myName.length; j++) {
    if (myName[j] === 'D') {
    newArray = [];


You may use pseudo text (Lorem ipsum, for eg.) but make it sufficiently long (with \ at line breaks) text and be sure to sprinkle your name in a few places.

text = "In diam diam, molestie Devon nec ullamcorper id, condimentum \
id mauris. Sed lacinia libero Devon vitae massa hendrerit vitae porttitor \
mauris porta. Praesent Devon dapibus vestibulum semper. Aenean posuere \
suscipit accumsan. Phasellus ac arcu Devon arcu. Phasellus sodales \
venenatis mollis. Fusce dignissim Devon mollis tortor sed fermentum. \
Pellentesque egestas, Devon mi in accumsan tempor, justo felis.";

The inner loop should be inside the if code body. Remove the console.log() statement.

Now let's examine that inner loop.

    for (var j = i; j < i + myName.length; j++) {    // remember the offset, i


I realized that if I read the paragraph more thoroughly that the 2nd for loop should have been inside the if statement. However, I have been trying and comparing my new code to other examples and am getting frustrated because I can not get the texts to push over to the new array.

var text = "Some text involved.";
var myName = "Devon";
var hits = [];

for (var i = 0; i < text.length; i++ ){
if (text[i] === 'D'){

for (var j = i; j < i + myName.length; j++) {
hits = [];



Oops, try again. It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable.


The above line is resetting the array with each iteration. Remove that line.