#5 Started to get lost here?


#1


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

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'){
        console.log("Yeah")}
    }
for (var j = i; j < myName.length; j++) {
    if (myName[j] === 'D') {
    newArray = [];
    newArray.push('Devon');
    newArray[0];
    }   
}


#2

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
        hits.push(text[j]);
    }

#3

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 = [];
hits.push(myName[j]);

}

}
}

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.


#4

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