I need a little help ending the second 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.

var text= "Hello my name is Luis. Did you hear well? It is \
Luis!";
var myName = "Luis";
var hits= [];

for ( i=0 ; i > text.length ; i++)
    {
      
      if ( text[i] === "L")
        {
           
           for (j =i ; j < (i + myName.length) ; j++)
            {
                hits.push(text[j]);
                console.log(hits);
            }
            
        }
      
        
    }


#2

for ( i=0 ; i > text.length ; i++)

You have wrong condition, should be:

for ( i=0 ; i < text.length ; i++)

console.log(hits) can be replace after for loop, because it prints symbols in all iterations.


#3

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