Help i don't know what's wrong with this


#1

var my_number = 7; //this has global scope

var timesTwo = function(number) {
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);

Oops, try again. Make sure you used the 'var' keyword inside the function!


#2

try this

var my_number = 7; //this has global scope

var timesTwo = function(number) {
var my_number = number * 2; // added the var keyword here
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);

They want you to create a variable using the var keyword


#3

Sloved thank you so much :smiley:


#4

Yes this exercise is not technically challenging but should rather point out that using var inside of a fucntion creates a new variable that only exists in this function. Which here leads to an effect called shadowing where you have 2 variables that have the same name where inside timesTwo only one is accessible although the other one is global.