Value of the variable is not printing


#1

I'm not sure what the code is missing.

Instruction:

On line 7, after the equals sign, call the function timesTwo with any parameter you want
Line 8 prints out newNumber. Notice how the value we return from timesTwo() is automatically assigned into newNumber.

My Code:

var newNumber = function(timesTwo) {
    console.log(newNumber);

};

timesTwo();

Error Message:

Oops, try again. It looks like you didn't print out the value of newNumber


#2

To use a function you need a few things.

1_ A variable
you have newNumber, but where is your original number :slightly_smiling: ?

var originalNumber = 2;

Note

I will give you examples along the way as I work through this.

```

2_ you need the function that will manipulate the input you put into it.

var timesTwoFunction = function(){
}

3_ next for the function to take an input you need to provide an attribute

var timesTwoFunction = function(number){
}

This is the same function we are just adding an attribute "number" to it
number could be x it doesn't matter, as it is just a placeholder for the real value passed to it

4_ now you need to add the logic into your function

var timesTwoFunction = function(number){
  newNumber = number * 2;
  console.log(newNumber);
}

5_ Now, before all of this works you will need to actually call the function.

timesTwoFunction(originalNumber);

Now all should be working!

Full code:

var originalNumber = 2;
var timesTwoFunction = function(number){
    newNumber = number * 2;
    console.log(newNumber);
};

timesTwoFunction(originalNumber);

Hope that helps :sunny:


#3

Sorry, but it doesn't work on mine. I don't understant why. It is written "Oops, try again. Your code doesn't look quite right. Did you set var newNumber = timesTwo(n), where n is whatever number you want? ".

My script
// Parameter is a number, and we do math with that parameter
var timesTwo = function(number) {
return number * 2;
};

// Call timesTwo here!
var newNumber = timesTwo(8);
console.log(newNumber);


#4

This code works for me maybe just refresh the page.