10. Global Vs Local Variables


#1


https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/2?curriculum_id=506324b3a7dffd00020bf661


var my_number = 7;

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

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

It keeps saying to me, "Oops, try again. Make sure you used the 'var' keyword inside the function!"

Someone please help!


#2

Well for one you need VAR my_number right under var timesTwo and I just ran your code through with the change and it passes so happy coding! :smiley:


#3

Hi, @bibleman13. I tried doing as you suggested. I have to sadly say, it did not work. Please could you post the right code here for me. As well as the reasons as to why there are differences in the code I set an you set!:innocent: I would much appreciate it.

Regards,

Arianator10


#4

Dear @bibleman13,

I am very sorry about the last post. It turns out all I needed to do was refresh the page, and ta da! It worked!

I am grateful for all of your help.

Regards,

Arianator10


#5

No problem man! I hate when that happens. You think nothing is working and bam it works! xD Glad to help!


#6

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