5. Second "For" Loop



Nevermind, I figured it out.

Error message:
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 = "Wade [redacted], adventurer, world-class lover, and hotshot \
programmer, has recently cleared the infamous Dungeon of Lewdocity. \
Sources close to Wade say that he appeared tired and chafed upon \
exiting the ruin that's claimed the lives of so many, but otherwise \
unruffled. A contingent of his strongest fans waited outside for nine \
days, many of them chanting, 'Wade! Wade! Wade!' until passing out.";

var myName = "Wade";

var hits = [];

for ( i = 0; i < text.length; i ++);
        if(text[i] === "W")
            for (j = i; j < (myName.length + i); j ++);


For Javascript the semi-colon-; is an End-of-Statement indicator.....

Thus if you use

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

the FOR-loop statement is =ended= and the corresponding code-block is not seen as to be part of this FOR-loop.

Also if you use i ++
then use it like i++

Please read
http://javascript.crockford.com/code.html <---JavaScript code-convention


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