Basic Node and Express - Use the .env File

Tell us what’s happening:
I have completed this exercise in a number of different ways all of which are successfully doing what the prompt is asking for but it won’t pass the test on freeCodeCamp and I do not know why. Please help me find what is going wrong here. Here’s my code:

app.get(“/json”, (req, res) => {
const caseVar = process.env.MESSAGE_STYLE;
var message = “Hello Json”;
(caseVar === “uppercase”) ?
res.json({“message” : message.toUpperCase()}) :
(res.json({“message” : “Hello Json”}));
// res.json({“message” : message});
})

Your project link(s)

solution: boilerplate-express2 - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36

Challenge: Basic Node and Express - Use the .env File

Link to the challenge:

A tertiary is not a general purpose replacement for an if statement.


Be careful with capitalization

The response object should either be {"message": "Hello json"} or {"message": "HELLO JSON"} , depending on the MESSAGE_STYLE value.

Even so, with this code here I still can’t seem to pass. Could it be an error happening that’s not in my control?

code using if/else:
app.get(“/json”, (req, res) => {
const caseVar = process.env.MESSAGE_STYLE;
var message = “Hello Json”;
if(caseVar === “uppercase”){
res.json({“message” : message.toUpperCase()})}
else (res.json({“message” : “Hello Json”}));
// res.json({“message” : message});
})

Did you miss this part of my post?

Your capitalization of the string must be identical in both cases. J is not j

Nevermind, I just passed after changing “Hello Json” to “Hello json” . I see it was all about the capitalization just like you said. Thanks alot JeremyLT

1 Like