Express + Node: Use The .env File (Broken Tester)

Tell us what’s happening:
its not passing the test, ive refactored it around 10times putting if else and terrnarys any way i can think of and its not passing, kinda fed up as they all work!!!

edit:ive also created a .env file and made a variable MESSAGE_STYLE=uppercase

Your code so far

// Use the .env file to configure the app 
let message = "Hello Json"
app.get('/json', (req, res) => {
process.env.MESSAGE_STYLE==="uppercase" ? 
  message = message.toUpperCase() :
  message = message
  res.json({"message":message})
})

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0.

Challenge: undefined

Link to the challenge:
https://www.freecodecamp.org/learn/apis-and-microservices/basic-node-and-express/use-the-.env-file

You should go back to the previous challenge and confirm what the message should look like if process.env.MESSAGE_STYLE is not “uppercase”. You have a typo.

Also, I do not recommend using ternary expression here. Ternary expressions are not meant to be a replacement for a simple if statement (which is all that is needed here). It makes it more complex than needed and less readable.

hi, thanks for the response, if the typo your refering to is the capital J on json every time ive tested it ive tried it with both capital and non capital just cause im used to things not passing for stupid reasons.

im not sure what the real differnce in tenary and if/else statements is one time i was just refered to them as shorthand for if/else statments so i use them just cause it looks nicer to me.

i’ve went back to the previous challenge and i passed it straght away i cant see the typo
im testing by going to the /json url and checking then changing the variable inside .env and checking again and it is doing what its ment to do
the first hour of work 2day was really enjoyable however ive spent 4hours on this and i really dont understand, im doing what it is asking me 2 do in the question it should say either “HELLO JSON” or “Hello json”
Here is 2 more atempts:

 let message = "Hello json"
 app.get('/json', (req, res) => {
 
   if (process.env.MESSAGE_STYLE==="uppercase") { 
   message = message.toUpperCase()
   } else {
   message = message
   }
    res.json({"message":message})
 })
 app.get('/json', (req, res) => { 
   if (process.env.MESSAGE_STYLE==="uppercase") { 
   res.json({"message":"Hello jSON"})
   } else {
   res.json({"message":"Hello json"})
   }
 })

The first of the last two code segments you posted above should work as long as you have not changed anything else in the project (as you originally posted in the Glitch link you once had in the post). If you are still not passing with the first of the last two you posted above, then please provide your Glitch project link again, so I can look at all the code.

The second of the last two code segments you posted above will not work. The reason the second will not work, is you have a different typo in the if statement code block:

res.json({"message":"Hello jSON"})

The message should not be “Hello jSON”. It should be “HELLO JSON”.

Also, like I said before, you only need an if statement (no else statement is needed) if you go with the logic of the first of the last two code segments you posted above… Ternary expressions are for assigning values to variables based on conditions and not meant to replace if/else statements that perform other logic except assignment.

Once you solve the challenge, I will show you how you could use a ternary expression that would make more sense.

Hi:)
I got it to work i actually just left it due to life commitments and started again and it worked so was probs somin silly mixed with me gettin a lil too frustated.
i would love to see some use cases for ternary expressions whenever you have time. Any help getting better is always welcomed thanks!