5. What is wrong here?


/*jshint multistr:true */
var text = "Hey, my name is Anthony, and I think I am pretty cool \
since Anthony is my name.";

var myName = "Anthony";

var hits = [];

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


This is the trigger for your 2nd loop. It will only work if the 1st loop comes across a "j" when it passes through all of the characters in your text variable. Since nothing in the text string has a "j", the 2nd loop never executes. The 2nd loop should execute when the 1st loop comes across the first letter of the myName variable. Change the "j" in your if condition to that letter.


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