Hi, I was doing this challange on Replit.
Since I cannot do it, I search an explaination with the hints and on the forum, finding this answer Basic Node and Express - Use the .env File. Actually my first question was: "Why the guy used response = "Hello world".toUpperCase();
without declaring a variable? So, using this suggestion I tried, added a variable but nothing happened. I tried to copy and paste his code, and magically worked BUT I didn’t understand why.
I wanted to retry but I have no chance to clear my progress only in this challange, so i need to understand with you guys.
The code I thought it was correct:
app.get('/json', jsonHandler);
function jsonHandler(req, res) {
let message = 'Hello json';
if (process.env['MESSAGE_STYLE'] === 'uppercase') {
message = message.toUpperCase();
}
res.json({
"message": message
})
}
The questions: why that guy uses a response
as it would be something that is already built in? Is it so or only a misunderstanding because a piece of code is not included?
But the most important: why my code doesnt’t work?
Can you share a link to your repl please? Do you have your environment variable stored in your secrets tab?
EDIT: I ask because your code passes for me. In the other code which you linked to ‘response’ is simply a variable name (undeclared).
That’s your live link. Can you share the link to your code please?
Oh yes, I edited the above message, thanks
Actually I have problems also with other challanges that I’m ALMOST sure they’re right. Sometimes I success and sometimes not in the same challange. I don’t understand why.
Is it possible that I didn’'t delete the other challanges and this disturb the test?
Actually, I just submitted your live link to the challenge and it passed, so there’s nothing wrong with your code. I don’t know why it’s not working from your end.
Maybe the problem is, since I’m new with servers, sometimes I modified the code without reset the server and then I check if the answer was right, but the fail regarded the previous wrong answer. I’m noticing now, in the other challanges, because my answers are right but sometimes I have no success.
If in doubt, always worth stopping and restarting your repl before submitting the link to FCC to verify the challenge…