In some cases, like this one, Codecademy seems to just look at your code and check whether you’ve declared what they asked you to declare. In this case, they seemed to want you to declare a specific variable, and when their regex evaluation didn’t detect it they threw you an error. (I’m not privy to the exact methods Codecademy uses to validate exercise input; simply guessing based on what I’ve encountered.)
Other times, what’ll happen is they’ll ask you to define a function for example, then validate your code by just calling the function with a range of arguments and checking that what comes out is right for each argument.
It can get a bit frustrating, having written perfectly viable code only to have Codecademy come back with an arbitrary “Sorry, that’s wrong” for what seems like no good reason, but it’s one of the unavoidable drawbacks of having an online learning platform automatically and instantly “grade” your code.
Eventually, you get used to it and just do what they’ve asked for in the exercise, even when it seems a bit repetitive or excessively… basic.