Cannot validate json response via a .env file (apparently)

I’m trying to resolve this task here:

but even though the code I wrote is correct, FCC validator says is not correct
The code does what is suppose to do, that is changing to upper case when the env variable


/** 5) serve JSON on a specific route */
var message = "Hello json";
app.get("/json", (req, res) => {
    message: message

/** 6) Use the .env file to configure the app */

if (process.env.MESSAGE_STYLE === "uppercase") {
  message = "Hello json".toUpperCase();
} else {
  message = "Hello json";

here is the live link:!/foam-cacao?path=myApp.js

why the code is not accepted? :frowning:

and the resut in the link is:

Because of the way the test is structured, you fail the test because your logic which determines the final value for message, is not contained within the “get” request callback function. Move it inside and you will pass the test.

Technically, your code works, but just not with the tests. In general though, this is a good reason to not create global variables. It is always better to declare variables within functions so as not to pollute the global scope.

1 Like

Thanks. But it should be a great idea to mention this in the task requirements :wink:
PS: this was a good lesson learned :slight_smile: