In “Use the .env File” challenge: first test says my code is ok while the second doesn’t.
Issue Description
Hello guys, I am working on “Use the .env File” challenge in the beta curriculum. I have managed to write my code with ES5 standards and when I test it on Glitch it works fine:
without any value for MESSAGE_STYLE, the output will be {"message":"Hello json"}
If I test my url https://lead-racer.glitch.me/ on freeCodeCamp page, the first test says my code is ok and takes me to the following challenge. However, if for any reason I test the url a second time, it says The response of "/json" does not change according to MESSAGE_STYLE
In my case, I commented out the working code to refactor it with ES6 standards and arrow functions. I made the usual tests from https://lead-racer.glitch.me/json and they were ok but when I tested on freeCodeCamp I got that error.
I thought I made some mistake with arrow functions (I don’t use them that much) so I brought back the previous code: surprisingly, the test on freeCodeCamp failed again
I found a way to pass the test, which is:
cut the code from Glitch IDE
refresh the Glitch IDE
paste the code again and wait for the Live label
refresh the challenge page on FCC
paste the Glitch URL
launch the test that will pass
avoid any additional test and go to the next challenge
However, I am not sure this is the best way to solve the problem. Any suggestions from other campers?
My Code with ES5
let messageObject = {"message": "Hello json"};
app.get("/json", jsonHandler);
function jsonHandler(req, res) {
if (process.env.MESSAGE_STYLE == "uppercase") {
messageObject.message = messageObject.message.toUpperCase()
}
return res.json(messageObject);
}
I just tried your code, it works fine. My code, on the other hand, doesn’t work… so I was wondering if the tests check for toUpperCase method specifically.
Then I tried a modification of your code as shown below. That didn’t work at all, which leads me to think that the testing unit might be bugged… Or having variable name as the key name confused the test unit somehow…
let message = {"message": "Hello json"};
app.get("/json", jsonHandler);
function jsonHandler(req, res) {
if (process.env.MESSAGE_STYLE == "uppercase") {
message.message = message.message.toUpperCase()
}
return res.json(message);
}