"Log it!" lesson issue


#1

// The program is telling me this script is correct but it can't be because all I get back from the log is 'undefined.' I'm a little confused about the bottom part and I know I must be doing something wrong. Could anyone double check me and explain this? Thank you!

var text = "If ever there was someone as awesome \ as Michael, they would certainly be named Michael \ so as to emulate Michael and his \ awesome accomplishments..especially in coding.";

var myName = "Michael";

var hits = [];

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

}

};

if (hits.length === 0) {
    
    console.log("Your name wasn't found!");
    
} else {
    
    console.log(hits[i]);
};

#2

this line:

console.log(hits[i]);

i doesn't exist anymore, it was only inside the second for loop, you just need to log the hits array, that is all:

console.log(hits)

#3

Hmm... when I do this and run it I get the following:

[ undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined ]


#4

this line:

hits.push("Hello"[j]);

j will hold the index of the letters you want to push into your hits array, to get the letters you need text[j], not sure why you have "Hello"[j]