Kept on trying Log It, did the correct answer, but it never worked


#1

I tried everything I could, but it keeps on showing me the error message and I could never pass it.

6/7 Log It https://www.codecademy.com/en/courses/javascript-beginner-en-XEDZA/0/6?curriculum_id=506324b3a7dffd00020bf661

Oops, try again. Did you remember to log the result of your search to the console?

/*jshint multistr:true */
text = "ooo oooh ahhh Henry \
chimie chung asssss Henry \
dance for me you rock Henry";

myName = "Henry";

hits = [];

for(i = 0; i < text.length; i++) {
    if(text[i] == myName[0]) {
        for(j = i; j < myName.length + i; j++) {
            hits.push(text[j]);
        }
    }
}
if(hits.length === 0) {
    console.log("Your name was not found");
} else {
    console.log(hits);
}




#2

Hi @64-bitman,

I tried running your code. It seemed fine to me and printed the correct results for me.


One thing you can try change is add the word "var" before variable text, myName and hits :

var text = "ooo oooh ahhh Henry \
chimie chung asssss Henry \
dance for me you rock Henry";

var myName = "Henry";

var hits = [];

I know this doesn’t change anything for your code in actual since those variables are global.

But, the checking system behind the exercise might be looking for that. (see if it works)

Else, everything is fine. If the above measure is not working, try refreshing it (logout and login again) or use different browser.


Help it helps :slight_smile:


#3

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