Your second for loop #5


#1

Can anyone help? It says it's not pushing values to the hits array.

var text = "Who knows what I'm supposed to write";

var myName = "Dan";

var hits = [];

for (var i = 0; i < text.length; i++)
{
if(text[i] === 'E'){
for (var j = i; j < myName.length + i; j++){
hits.push(text[j]);
console.log(hits);

    }
}

}


#2

I know the text is supposed to say 'D' instead of 'E'. Forgot to change that for the sake of this question. But even then, it's still saying the same error message.


#3

your name is not present in the string stored in text variable, so i can't be found


#4

Instructions
Declare and set the following three variables:

01.var text, and make it a string containing some text. Place your name in there a couple of times!

For ex. var text= " "Hey, Dan how are you doing My name is Dan";


#5

also log the hits array (console.log(hits) ) to the console under your existing code (and outside all your loops!)


#6

Link the page where you're stuck!

Update...

If you're at first lesson of exercise then you've to follow along.
You'll be adding different parts of code in next lessons.

If you're at last part of lesson as you can see the last part is log it! and victory

Then you need to go through the exercise and read instructions, You're missing
this..

I hope it helps!


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.