Second for loop, What's wrong


#1


var text = "snuffy";
var myName = "Elmo";
var hits = [ ];

for (i = 0; i < text.length; i++) {
if ( text[i] === 'E') {
for (j = i; i < myName.length + i; j++){
hits.push(text[j]); }
}
};
console.log(hits);

/*jshint multistr:true */


Replace this line with your code.


#2

In your second loop you are to be checking if j is less than the myName variable and not i

[quote="cjudd42, post:1, topic:68853"]
i < myName.length
[/quote]

to,

j < (myName.length + i)


#3

Changed that still get the same 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.


#4

Does anyone have the correct code, I can't get this to work at all.


#5

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