6. Log It! If/else, ReferenceError hit is not defined


#1

I am having trouble with the If/else (2nd one), because I'm doing exactly what it wants, and It still says:
"ReferenceError: hit is not defined"
and It says,
"Oops, try again. Did you remember to log the result of your search to the console?"
I know the text is funny but here is my code:


/*jshint multistr:true */
var text = "I was walking up the street and \
said hi to my neighbors and they said \
'Hi Jake!' back to me, and I smiled because I,\
Jake, am very polite! And Then I saw... \
PINK FLUFFY UNICORNS, DANCING ON RAINBOWS\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
And they were calling to me! Jake! Jake!\
Come with us, become a pink fluffy unicorn\
and dance on rainbows! And so I turned into a...\
PINK FLUFFY UINICRON DANCING ON RAINBOWS! But I, I\
am speacial, I can breathe fire, and poop out rainbows\
and candy! Well that's my story, signing out,\
-Jake, The Pink Fluffy Unicorn, Dancing On Rainbows!";
var myName = "Jake";
var hits = [];
for (var t = 0; t < text.length; t++) {
if(text[t] === "J") {
    for (var i = t; i <= myName.length + t; i++) {
    hits.push("Jake")
}
}
}
if(hit.length === 0) {
    console.log("Your name wasn't found!");
}
else {
    console.log(hits);
}


#2

HI first here

hits.push("Jake")

you should .push() inside hits text[i] like that

hits.push(text[i])

then here

if(hit.length === 0)

you wrote hit instead of hits


#3

Thank you so much! I really needed help and both things were vital things in getting the answer! Thank you!


#5

you forgot a semi colon after

hits.push("Jake")

it should be

hits.push("jake");


#6

Thank you so much! but I passed that lesson and now need help on Code your own adventure 2! If you see something about a switch code topic HELP! click on it and try to help. Thanks again!


#7