Your second "for" loop 5/7


I am very lost with whats going on in this part of the lesson

Here's my code:

    var text = "Lets dispel this fiction Stephen that\ Barack Obama doesn't know";

    var myName = "Stephen";

    var hits = [];

    for (var i = 0; i<text.length; i++){
        if (text[i] === "S") {
            for(var j=i; j<=myName.length; j++){

This is what I get when I submit:

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.


Hi here (var j=i; j<=myName.length; j++ you missing that

j<= (myName.length +i)

So its should be like that

 for(var j=i; j <= (myName.length + i); j++)


Can you read this and see if my own word explanation makes sense relative to the exercise?

So essentially, you're nesting another "for" loop within the first forloop. Instead of the interval i starting from 0, there is a new, internal interval, interval j. j is assigned to do i's work if the original for loop comes upon a capitalized "S". After finding that captialized "S", the nested for loop will copy or "push" the length of "var myName" (seven characters, for Stephen), one character at a time into the empty "hits" array, and console log will print the results out.