Hello world!
I am trying to resolve this exercise in two different ways:
Way 1:
In a separated conditional, check if mySecret === ‘uppercase’ and then apply toUpperCase() method to the variable which saves “Hello Json”.
Then send this variable to the res.send:
const mySecret = process.env['MESSAGE_STYLE']
let response = "Hello Json"
if(mySecret === 'uppercase') {
response = response.toUpperCase();
} else {
response = "Hello Json";
};
app.get('/json', (req, res)=>{
res.send({"message": response});
});
Way 2:
Set the conditional directly in the get request and just send “HELLO JSON” or “Hello Json” as appropiate:
const mySecret = process.env['MESSAGE_STYLE']
app.get('/json', (req, res)=>{
if(mySecret === 'uppercase') {
res.send({"message": "HELLO JSON"});
} else {
res.send({"message": "Hello Json"});
};
});
Neither of the two ways is accepted as valid by Freecodecamp and I tried to change the endpoint from ‘/json’ to ‘/’ and the Replit’s browser prints the information correctly in both ways.
Any suggestion?
solution: https://replit.com/@jmonloop/boilerplate-express
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36
Challenge: Use the .env File