Arrrggghh! ... codecademy ... why oh why 10/13?!

#1

the lesson on global and local variables is simple, but you really threw me for a loop by defining

my_number AND timesTwo

as the number 7

why would you define both the same number? It only serves to confuse and obscure an otherwise simple but important lesson. Once I substituted a different number for timesTwo, the lesson was clear as day. I thought the 7 had some kind of significance. Dear codecademy, please remember that we are trying to learn this stuff, and every comma, semi-colon, + sign = sign or whatever else is scrutinized by your students for meaning and significance, please don't assume that we know anything. I guess we are just like computers

#2

Is not `timesTwo` a function?

``````var my_number = 7; // this has global scope

var timesTwo = function(number) {
var my_number = number * 2;
console.log("Inside the function my_number is: ");
console.log(my_number); // 14
};

timesTwo(my_number);

console.log("Outside the function my_number is: ")
console.log(my_number); // 7``````

Because we declare `my_number` with `var` inside the function (local scope), it is a different variable from the one in global scope.

#3

Thank you, medve, for the suggestion. The moment I used different numbers for timesTwo, I understood the difference between global and local variables.

#4

I'm still wondering where the inclination came from to replace

timesTwo = my_number * 2

with

var my_number = number * 2

The difference between global and local is understandable, but I'd prefer to see a working example rather than some purposefully errant problem. For instance, I just typed in the above and passed, though now I'm wondering what/why/when do/did I have to change that variable?

#5

`timesTwo` is a function, not a value. It sets a local variable, `var my_number` which now casts a shadow over the global `my_number`. Inside the function only the local variable can be referred to. The global would need to be referenced with `window.my_number` to be visible inside the function.

``````var my_number = 5;
function multiply(my_number) {
return my_number * window.my_number;
}
console.log(multiply(7)); // 35``````

#6

Thanks medve,

Although the lesson is pretty straightforward, and I understood that timesTwo was a function. Changing the number did help me understand the concept a bit more concretely as opposed to using 7 for both. I think it's because I'm a very visual learner.