JavaScript-second for loop


I am trying to figure out what is wrong with my programming logic. I keep getting the error:

"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."

myName's text does appear in the text variable. I don't understand why the loop doesn't detect it.

my code is below.

/*jshint multistr:true */
var text="Hey, how are you doing?\ My name is Rick Swordfire..";
var myName = "Rick Swordfire";
var hits = [];

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


Your problem is here,

You are incrementing your for loop before the condition,

for loop syntax

for (initialization; check; increment) {


for (initialization; increment; check) {


That fixed it. Thank you.


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