5:Your second "for" loop, need completed code!



I need someone to post a working code to pass this lesson number 5 in order to learn what is wrong with my code to pass this lesson, thanks.

/*jshint multistr:true */
var text = "Hello there!";
var myName = "Sanjay";
var hits = [];

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



So it seems like there's a few issues with the code you've provided. First, in your 'text' variable, you do not provide your name, so the program will never return the desired result. It should appear as
var text = "Hello there! My name is Sanjay!";

Second, the first part of your 'if' function should only contain a string, the string being the first letter of your name, like this:
if (text[i] === "S") {

Lastly, inside your second 'for' loop, myName.push('hello'); doesnt really work. The variable myName is not set as an array, so the .push will cause an error. Use the 'hits' function to push the results of the 'for' loop into the array, like so:



it says that my loop isnt pushing values to the hits array
var text = "hi iam chris and u know chris";
var myName = "chris";
var hits = [];
for(var i=0; i < text.length; i++);{
if (text[i] === "c"){
for(k=i; k <= i + myName.length; k++);{


I am having the same problem so I can't explain everything but I do see that you haven't declared k as a variable in your second for loop.