Grossly lost


#1


https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661#

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.


var text = "josh josh josh";
var myName = "Josh";
var hits = [];

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


#2

Hint: Strings are case sensitive.


#3

your name (Josh) should be spelled with uppercase first letter in your text variable.

Also, this line:

if (text[i] === myName["j"])

you should check if text[i] equals the first letter of myName (myName[0]), which brings us back to @tekkie1618 point, comparing J with j would be false, since strings comparison are case sensitive.


#4

Thank you sir.

Updated code, still erroring: (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.)

var text = "Josh testing 123";
var myName = "Josh";
var hits = [];

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


#5

^ you don't seem to have done this change, you still use myName["J"] which is not existing. it is either myName[0] or "J". J is not a valid index for myName


#6

Orignally what I thought was that you meant to change it from a lowercase to a capitalized J. Thanks for the help!!


#7