"Victory!"...but I never actually found my name. What's wrong with my code?


#1


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


The exercise says "Congratulations! You've finished the course!" but the output of my code in the top right says "Your name wasn't found!"

I don't really care that the exercise thinks I'm done. I want to know how to fix my code so that it finds the name I specified. Can anyone anyone help me identify where I'm going wrong?


/*jshint multistr:true */

var text = "This is just a test, Rob.";

var myName = "Rob";

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(text[j]);
        }
    }
    }

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


#2

Remove the semi-colon. There is no semi-colon in the structure of a for loop (or an if statement).

for (...) {
    if (...) {

    }
}

#3

Wow, I can't believe I missed that. Thank you so much!!


#4

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