For Second Loop Help


#1

Need help with second loop getting error.

Error code: Oops, try again. Careful: your second 'for' loop should stop when it reaches its current point in the string + myName.length


Replace this line with your code. 
/*jshint multistr:true */

var text ="yash, yash yash yash \
        yash yash";

var myName = "yash";

var hits = [];

for (var i = 0; i > text.length; i++);{
   if (text[i] === "y") {
     for ( var j = i; j > myName.length; j++); {
        hits.push(text[j]);
     }
   }
}


#2

First Loop
var i must be greater than text.length?

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

I think not.

AND

for (var i = 0; i > text.length; i++); // for what is that semicolon?

Second loop

Again var y must be greater than myname.length?

 for ( var j = i; j > myName.length; j++); // and again for what is the last semicolon needed

And please think about j > myname.length here is something missing


#3

Fixed :slight_smile: instead of for ( var j = i; j < myName.length; j++) had to type for ( var j = i; j < myName.length+i; j++)


#4

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