Curious why this isn't working


My name is not printing in the console. But the tutorial says I’ve succeeded. Can someone tell me why please? Thanks!

/*jshint multistr:true */

var text = "Garrett James, Garrett James, always felt a little \
strange about the way that human beings treated the world.";

var myName = "Garrett James";
var hits = [];

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

if (hits.length = 0){
    console.log("Your Name wasn't found");
else {


your loop condition:

for(var j = i; j < 0 + myName.length; j++)

why 0 here?



why push i to the array?


if (hits.length = 0)

a single equal sign means assign, so you give the array a length of zero instead of checking of the length equals zero


Thanks for asking those questions, it helped me to identify my issues and work it out. Much appreciated.


That is even better that my question identify your issues and that you could figure out the solution yourself, well done :slight_smile:


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