Code is not working


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 \
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 = [];


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?




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