Your second "for" loop


#1


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

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.

Why isnt this working?

var text = "blab blab blob Joey Joey Joey";
var myName = "Joey";
var hits = [];
for(var i = 0; i < myName.length; i++);
{
   if(text[i] === "J")
   {
for(var j = i; j < (i + myName.length); j++)
{
    
     hits.push(text[j]);

}}}
console.log(hits);


#2

The above line should not have a semi-colon at the end.


#3

...
var text = "blab blab blob Joey Joey Joey";
var myName = "Joey";
var hits = [];
for(var i = 0; i < myName.length; i++)
{
if(text[i] === "J")
{
for(var j = i; j < (i + myName.length); j++)
{

 hits.push(text[j]);

}}}
console.log(hits);

...

I tried it without but still doesnt work


#4

Your code looks okay, now. Try to refresh the page and run again.


#5

Oh nevermind thanks in the first for loop i put... i < myName.length ...instead of... i < text.length ...


#6

Boy do I need new glasses. Looked right at it, d'oh!


#7

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