[FAQ] Common Problems #Read Me


#1

Hey everyone, this is a collection of FAQs from the old forums that I am copying over here for easier access.

Hope they help,
The Codecademy Moderators.


1st problem - Quotes on a Variable

Once a word has been declared as a variable
it becomes a reserved word.
If you wrap it in quotes it loses the variable power because it becomes just a string of characters.

Examples:

var myCountry = "USA"; 
console.log(myCountry.length);
console.log(myCountry.substring(0,3));

"USA" is wrapped in quotes because it is a string of characters.
myCountry should not take quotes because it is a variable.
A variable is a memory location where we can save data.

var myNumber = 333;

Although 333 is data just like "USA", it does not get wrapped with quotes because it is a number. Only strings of characters get wrapped in quotes.
If I write "333", the value becomes a string of characters, 3 being the character. The problem with this is that it can not be used in math.

See my later post for more clarification on this.


2nd Problem - if/else statements

if/else statements have a very strict structure you must follow:

A typical if () statement looks like this. Depending on what you are checking for, the else if and else blocks may not be needed. Note how the { }, ( ) and ; are used.

if (this condition is true) {
    do something;
} else if {
    do this other thing;
} else {
    do something different;
}

You need to make sure all your { }are used correctly and in the right places. Before writingelse ifyou need to have closed yourifstatement with a}.

Also notice where the ; are used. They are NOT used after the condition is declared like this if (condition) ; that will cause your program to break. ; should only be used in the statements within the if block as they signify the end of an instruction.


Thanks to the following users, who were brilliant enough to make the original posts!
Tony de Araujo
Albions


#5 Can't find the problem with my code
#2

#3

Hello I don't understand this kindly please help me out


Gummy
#4

Thanks for these two usefull explanations.

Generally, JS lessons in Codecademy do not provide me the background information, support and hints I was expecting.

Feedback in the exercises is too general, or even incorrect.

I gave up in lesson 5.Both Choices are the same (Rock, Paper, Scissors) after checking my code over and over again for a "syntax error", and finally discovering I forgot a ****ing ! in the phrase "The result is a tie!" The ! is not even in the code shown in the hint!!!!

And moreover, what do I learn about coding JS correcting this error?!?!

Seriously, very disapointed in this Codecademy course.


#5

The courses are rather old and could do with an update, the problem is that the Correction Test that checks your code is looking for that specific string, and they cant program a check to look for every little variation on that string. The JS courses are useful though, just keep trying with it and making sure to copy and paste the strings they are asking for exactly.


#6

so sorry, I don't understand it too.


#7

@boardninja04230 @esperanceumutoniwase
Sorry for the super late clarification:
As stated the original post was by @tarau but I will try to explain it.

He is saying that a variable name is not a string. Using the same example he did:

var myCountry = "USA";
console.log(myCountry.length);
console.log(myCountry.substring(0,3));

This means that myCountry is not the string "myCountry" but is the variable linked to the string "USA". Hence:

console.log(myCountry.length); // Will return 3 as "USA" is 3 characters long.
console.log(myCountry.substring(0,3)); // Will return "USA" not "myC".

If you wanted to find the length of the string "myCountry" you could have to put quotes around it like so:

console.log("myCountry".length); // Will return 9
console.log("myCountry".substring(0,3)); // Will return "myC"

Hopefully I have clarified that words without " " around them only link to the variable, and quotes are needed if you want to manipulate the actual string.

Let me know if that cleared things up!


Java scripist
#8

3 posts were split to a new topic: myCountry error


#9