What am i doing wrong?


#1

/*jshint multistr:true*/

var text = "random stuff that I Ben don't want to have to do\ at all Ben I really think that this random text is boring";

var myName = "Ben";

var hits = [];

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

What am I doing wrong? I have no idea. Somebody help me


#2

I think the second for never gets executed. If i = 10, then j = 10, but 10 is not bigger than 13(10+3). Try that first, after that I see other issues.


#3

In

">" should be "<". Typos, can be so hard to catch.


#4

The code you have below that for line looks wrong to me too.
the hits = [] line will empty the hits array.
You're pushing from myName to hits, and I think we're supposed to push from the 'text' array.
hits[0]; doesn't do anything.

try:
for (var j = i; (j < i + myName.length); j++){
hits.push(text[j]);
}
}
};