Variables? 25 and 26


#1

I had a hard time with lesson 25 but executed the program like so:

var myCountry = "The United States of America";
console.log("The United States of America".length);
console.log("The United States of America".substring(0,3));

It passed.

Then onto 26 and wrote my program in similar fashion and it too passed:

var myName="Ariana";
console.log("Ariana");
myName="Ar"
console.log("Ar");

My question is where are we storing variables if it's not to recall? When I was doing lesson 25. I was under the impression it should have been:

var myCountry="The United States of America";
console.log("myCountry".length);
console.log("myCountry".substring(0,3));

As in by defining the variable, the value had been stored. Meaning (as per the lesson) I would be able to use the shorter "myCountry" vs "The United States of America." If I have to type out "USA" every single time, that's not easier than just inputting the variable. Same with lesson 26. Am I really updating the value if I have to manually print which value I want every single time? Maybe I'm thinking too basically but as I peruse through these forum post, I see a lot of students having the same "Variable" issues.


#2

The value was stored in the myCountry variable.

var myCountry="The United States of America";
console.log("myCountry".length);

Instead of using the myCountry variable, you instead used a string "myCountry".

The correct way to log the myCountry variable is like this:

console.log(myCountry.length);

#3

Ahh, so I used a string instead of the variable. Then does that mean the program is judged only on output rather than written code? Based on your explanation, I did not do the assignment as it should have been written.

P.s.
Thank you for the clarification. The error code it was giving me was throwing me for a loop!!


#4

Thanks! That was super helpful!!


#5

The code checker is far from perfect :slightly_smiling:

It is good to look at your program and the results and decide for yourself if they seem reasonable.

Always ask if you have doubts. :green_heart:


#6

A post was split to a new topic: 25. This is how i made through!