Basic JavaScript - Add Two Numbers with JavaScript

**Tell us what’s happening: **
Hello, just wondering if maybe we should be using CAPS since “sum” is being declared as read-only? The previous lesson suggested it as best practice and now im being prevented from doing it is there something im missing?

Your code so far

const SUM = 10 + 10;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.26

Challenge: Basic JavaScript - Add Two Numbers with JavaScript

Link to the challenge:

The only reason it’s not passing that way is that it expects the variable to keep the name that they had given it, which would be the variable name that the test suite is looking for.

I understand that and address that in my question "Hello, just wondering if maybe we should be using CAPS " due to “sum” is being declared as read-only ~according to best practice which was stated in the previous lesson.

Ill try to be more direct - What is the reason for not using best practice?

You are saying:

const => USE ALL CAPS

That isn’t quite the convention/best practice. The convention is:

const + global variable for larger program => USE ALL CAPS

I will make as many variables const as I can, but I only use ALL CAPS for variables that are important constants in the global scope.

For a math example of what I mean:

const PI = 3.14159;

function f(x) {
  const sinArg = PI * x;
  return sin(sinArg);
}

function df(x) {
  const cosArg = PI * x;
  return PI * cos(cosArg);
}

No i am not the one saying it as stated in my comment it was in the previous lesson

" Note: It is common for developers to use uppercase variable identifiers for immutable values and lowercase or camelCase for mutable values (objects and arrays)."

The code further generates an error if you dont change the fcc value to FCC.

" You should change

fCC

to all uppercase."

So I will try one more time. What is the reasoning? < That is my question since sum doesnt need to be change. This is inconsistent and confusing.

I’m not sure you understood my comment.

The convention is not to use ALL CAPS every single time you see the const keyword used.

The convention is to use ALL CAPS when the const keyword is used and the value is a GLOBAL constant for a larger piece of code.

The exact meaning of “a GLOBAL constant for a larger piece of code” isn’t really easy to explain until you get further into the curriculum, which is why the lesson you are quoting gave you a rough rule of thumb.

That does answer my question thank you.

1 Like