Need Help with "6.log it"


#1


I have no idea why my code is not correct; I can't see it!

Please help me out!


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


I'm getting something like this:
[ 'B',
'l',
'a',
'h',
' '


text = "Blah Blah Blah Chinh\
Blah Blah Blah Blah Chinh Blah\
Blah Blah Blah Chinh";

var myName = "Chinh";
var hits = [];

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

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


#2

HI your if statement you didn't open and close it

if (text[i] === "C");

and remove the ;

if (condition) {

}

#3

Hey wizmarco, thank you so much for responding!

After closing the if statement, the issue remained, but I found the real culprit:

the semicolon ";"

After I removed it, the code worked perfectly!


#4

hey, the output of the code for me was
[]
it says it is correct, but i don't understand why, please explain


#5

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