Tell us what’s happening: Describe your issue in detail here.
My issue is that I’ve written this code several different (correct) ways in javascript and the challenge is not recognizing the correctness of the code. Maybe I am missing something here, but the .env file feature is deprecated in Repl. There is no way to include it in the file system. The SECRETS tab has the environment variable features, which I have used and tested that it logs correctly that it works in the console, but I’m unable to confirm it within the FCC challenge itself.
I’m looking to essentially make the “Hello json” message all uppercase upon the condition that the environment variable exists and otherwise it would print the regular JSON message. I’ve written this in a multitude of different ways (please refer to the commented-out piece of code) but can’t seem to get it to fully function for the sake of the project. Do you have any clue as to what I might be doing wrong here? Any guidance will help. Thanks
Absolutely nowhere have you written HELLO JSON or "Hello json".toUpperCase(). (Edit, missed the second, but you shouldn’t need a return there) That string is the only thing that should be uppercase.
I understand that string is the only thing that should be uppercase. I wrote HELLO JSON in the second code block above. If you are aware of it, what exactly am I doing wrong? I would like to learn from my mistake… thanks
I do have that 2nd piece of code in the Replit… and have tried to complete the challenge with that code, but it does not accept the solution. I’m not sure what else to try :- (
// This shouldn't be here, but it appears to be harmless
require('dotenv').config();
var express = require('express');
var app = express();
// This shouldn't be here, harmless but confusing
const mySecret = process.env['MESSAGE_STYLE'];
app.use('/public', express.static(__dirname + '/public'));
app.get('/', function(req, res) {
console.log("Hello world");
res.sendFile(__dirname + '/views/index.html');
});
app.get('/json', (req,res) => {
if (process.env.MESSAGE_STYLE === "uppercase") {
// You shouldn't need 'return' here but is harmless
return res.json({
"message":"HELLO JSON"
})
} else {
// Same comment about return
return res.json({
"message":"Hello json"
})
}
});
module.exports = app;
The route code is correct, but if you go to the /json route you can see it sends the lowercase version which it wouldn’t do if you have set up the environment variable correctly.
The key and value should not be quoted, so make sure you add uppercase and not"uppercase" as the value.
If I clone your replit and add the key and value it passes the test.
OK, thank you Jeremy. I’ve adjusted the code snippet in my Replit to reflect your comments but it’s still not working. I suspect the need to create a new Replit repo for this particular challenge. I’ve been stuck on this for two days now without resolution, the only thing I haven’t tried is attempting to create a new repo. I will report back shortly!
Yes that’s exactly what my SECRETS tab looks like. That was why I was confused why it wasn’t working in the original repo… created a new Replit repo with the proposed correct solution and a SECRET tab as well, still not working. I’m really not sure what to do. This is the new repo: https://boilerplate-express-1.emilypmendez.repl.co
Thanks. Trying your suggestion of using uppercase without the string ticks… not sure this value is working either. Attached a screencap of what I’ve got on a new repo, but it’s not passing the challenge.
If you strip the quotes there, you are referring to a variable called uppercase that is not actually defined. Inside of the SECRETS is where you shouldn’t have the quotes.
I had the wrong picture before:
This is what you should see in the ‘Raw Editor’ for the secrets.
Okay that is new! Thanks. I tried this update within the SECRETS but it ultimately wasn’t passing the test because I had to restart the console server and then try passing the test again. I was feeling really quite stumped on this challenge, thanks for all your help! Happy new year!