5/7 your second "for" loop / Help?


This is my code. If you know what I did wrong, please help and explain because I don't understand:

/*jshint multistr:true */
var text = "Shae Shae Shae" ;
var myName = "Shae";
var hits = [];

for (var i = 0; i if (text[i] === 'S') {
for(var j=i; j < (i+myName.length); j++); {
hits.push( text[ j ] );

It works but this is what it returns:
[ ' ', ' ', undefined ]

If you can help, thanks!



The for statement creates a loop that consists
of three optional expressions,
enclosed in parentheses and separated by semicolons,
followed by a statement or a set of statements executed in the loop.


for ([initialization]; [condition]; [final-expression]) {

As a semi-colon-; is an End-of-Statement indicator for the Javascript interpreter,
and you are using the semi-colon in your FOR-loop definition,

 for(var j=i; j < (i+myName.length); j++);

the statement-body will NOT be executed..........

Remove the semi-colon-;



I removed the semi-colon, but it resulted in the same output. Any other ideas?


What is this FOR-loop statement of yours ...???

Please read