Completely Stuck


#1


Been stuck on the second foor loop for hours.

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) {
            hits.push(text[j]);
        }
    }
};


#2

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.


#3

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


#4

What would the parenthesis change?


#5

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.


#6

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


#7

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


#8

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


#9

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.