Global/Local Variables code not working?


#1

I am stuck on this lesson. I believe I understand it and I've followed the instructions but I cannot progress as the code fails to work and I cannot understand why.

I've searched and read many other discussions. I've tried to copy/paste answers others have given, but I see no difference in their code vs mine.

Here is my code.

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);
};

timesTwo(7);

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


#2

Your missing a semicolon right there. Also, if that doesn't make it work then could I see a link to the exercise?


#3

This discussion also explains Global vs Local very well if there is still confusion. Several people gave detailed explanations in it.


#4

Thank you! This was driving me mad.


#5

np, I'm glad to help :slight_smile:


#6

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