Tell us what’s happening:
I am having issues getting the freecodecamp tester to give me a pass on the test. I am able to get the correct output from (bas-url)/json but for some reason it still fails the test…
Your code so far
myApp.js:
var message = 'hello json';
if(process.env.MESSAGE_STYLE === 'uppercase'){
message = message.toUpperCase();
}
app.get('/json', function(req, res){
return res.json({"message": message});
});
.env:
MESSAGE_STYLE=uppercase
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
.
Challenge: Use the .env File
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
var message = 'hello json';
. Perhaps try changing this to var message = 'Hello json';
as I see that in the previous challenge that word is capitalized.
Just a blind guess tho.
Hi @Larquist
try putting the test inside the /json
route handler:
app.get('/json', function(req, res) {
var msg = process.env.MESSAGE_STYLE === 'uppercase' ? message.toUpperCase() : message;
return res.json(msg);
});
This didn’t work for me but I was thinking the same thing!
Not quite. For some reason it didn’t like the one line if statement. It would just keep loading in the browser. I had to do it like this…
app.get('/json', function(req, res){
var message = 'Hello json';
if(process.env.MESSAGE_STYLE === 'uppercase'){
return res.json({"message": message.toUpperCase()})
}else{
return res.json({"message": message})
}
});
And it worked! Thanks though, you put me on the right track!
2 Likes
Thanks. It worked. I was struggling for hours