Code is not working


#1


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


It says: 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 = "jfasdlfj jack ajdskl \
fjdskjackjack.";
var myName = "jack";
var hits = []
for(i = 0; i < text.length; i ++); {
       if(text[i] === "j"){
           for(var j = i; i < i + myName.length; i++); {
            newArray = [];
            newArray.push('i');
            newArray[0];
           }
       }
}


#2

Syntax of for loop.

for (first_part;second_part;third_part) {
    //your code
}

You have put semicolons after your for loops..(which is against the syntax rule of javascript)

like one of the loop..

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

Other thing to note..

for(var j = i; i < i + myName.length; i++) your loop iteration variable is j but youre incrementing i ?

also why you need newArray ?

your Array is hits that you defined outside of function?
also You have to push the characters not index of it?

like...

hits.push(your_letter);


#3

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