Completely Stuck



<Below this line, add a link to the EXACT exercise that you are stuck at.>

Been stuck on the second foor loop for hours.

<In what way does your code behave incorrectly? Include ALL error messages.>

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.


/*jshint multistr:true */

var text = “I am Guy, nice to meet you”

var myName = “Guy”

var hits = ;

for (i = 0; i === text.length; i += 1) {
if (text[i] === “G”) {
for (var j = i; j === (i + myName.length); j += 1) {

<do not remove the three backticks above>


Put () sign around the text variable and a ; sign at the end

(“I am Guy, nice to meet you”);

Change the === to a < sign in the first for loop.

i < text.length;

Change the === to a < sign in the 2nd for loop.

j < i + myName.length;

At the end exchange (text[j]) with (“Guy”)

That should do it.


No, don’t do this. The quotes are enough to delimit the string.


What would the parenthesis change?


Nothing, except the readability. It makes little or no sense to have multiple delimiters on a value, and wrapping a value in parens is superfluous code.


Would it work the same way if you only added parenthesis with no quotation marks?


No. String values need to be in quotes. Remove the quotes and the interpreter will see words as undefined variables.


That’s what I thought. Thank you for the clarification.


It is fairly common to see,

    return ("some string value");

This is not invalid (and neither is yours, above), but again, it is superfluous. Some organizations may have this specified as required in their inhouse style guide, but it would be for their reasons, not for the sake of the code, itself.