Please help, don't know what else to do

Tell us what’s happening:
i got to this challenge to create an program to output json response based on whether request is in uppercase or not. I have writen various program instruction yet saying the same thing

here is my last code please help out:

if(mySecret.toUpperCase() === "uppercase"){
     res.json({
       "message": "HELLO JSON"
     })
   }else{
     res.json({
        "message": "Hello json"
     })
   }

thanks in advance :grin:

Your project link(s)

solution: https://replit.com/@yunishello/boilerplate-express

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 OPR/78.0.4093.231

Challenge: Use the .env File

Link to the challenge:

1 Like

If mySecret==="uppercase" and you convert that using toUpperCase(), will it ever equal "uppercase"?

3 Likes

no, it won’t. But according to their program it mandatary to include toUpperCase() method

here is their own program

if (process.env.VAR_NAME === "allCaps") {
  response = "Hello World".toUpperCase();
} else {
  response = "Hello World";
}

could you please explain the codes?

1 Like

And for this code it flags errors

1 Like

Note where they’re using toUpperCase. Is it in checking the secret, or is it converting the message based on the secret

2 Likes

it converting, but in my case the code isn’t working


/home/runner/boilerplate-express/myApp.js:10
       response = "hello json".toUpperCase()
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This was the error I got

1 Like

Have you declared response at this point? Perhaps before the if?

IIRC, node ruins in strict mode, so a variable must be explicitly declared (let foo) at or before being initialized:

let foo;
foo="bar";

// or
let foo="bar";
2 Likes

Its a bit confusing, you describe one challenge, but you give link to a different challenge. The FCC challenge has different instructions from the ones you try to accomplish. You need to put the response in upper case, if the specific environmental variable value is equal ‘uppercase’. So first you need to figure out a way to access that environmental variable and check if its value is equal to ‘uppercase’. The lesson has an explanation on how to access an environmental variable value.
Once you have the variable value and if its equal to ‘uppercase’ you should apply toUpperCase() to the response message, before you send it.

2 Likes

I think my code suppose to be like this

const mySecret = process.env['MESSAGE_STYLE']

if(mySecret === "uppercase"){
     res.json({
       "message": "Hello json".toUpperCase()
     })
   }else{
     res.json({
        "message": "Hello json"
     })
   }

Please correct me if am wrong

Did you try it? See if it passes? The test can tell you better than we can. It looks better though, yes.

1 Like

it not passing through, but it correct according to my test

Should that be. res.json() or res.send()?

1 Like

it should be in json format

Again @yunishello you are exporting just a single app method rather than the whole app:

module.exports = app.get("/json", function (req, res) {
  // res.sendFile(__dirname + '/views/index.html');
  // console.log(mySecret)
   if(mySecret === "uppercase"){
     res.json({
       "message": "Hello json".toUpperCase()
     })
   }else{
     res.json({
        "message": "Hello json"
     })
   }
  // console.log("it is well")
  // res.json(req.time)
});

You are supposed to just export your app. And add all the methods above that.
Your file should look like:

// imports
vax x = require("foo");

// your methods
app.get()
app.post()
app.public()

// exporting the whole app with all its current methods
module.exports = app;

Hope this helps.

2 Likes

Oh, i never knew that what i was suppose to do
right away :smiling_face_with_three_hearts:

Well the starter had this shape:

var express = require('express');
var app = express();




































 module.exports = app;

You have to scroll a bit to find the module.exports, and they never asks you to delete the file or its content.

It can probably be improved and make explicit that those lines are not to be modified, like with other front end challenges

2 Likes

Okay, thanks a lot
I will work on that too

Maybe this would help:

// You just check if the variable 'mySecret' is the same like 'mySecret' When it hase 'toUpperCase()'
if(mySecret === mySecret.toUpperCase()){
     res.json({
       "message": "HELLO JSON"
     })
   }else{
     res.json({
        "message": "Hello json"
     })
   }

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.