Lesson: Return Key Word - Function Syntax Error


#1

Could someone tell what missing in the code?

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

};

timesTwo();

Instructions:

In our example we have a function called timesTwo() that takes in a number and returns the number multiplied by two.

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.

#2

You don't need timesTwo();, but this lines instead

var newNumber = timesTwo(7); // you can pass any number, I passed 7, it's important you assign it to new variable
console.log(newNumber);

You also need to modify your timesTwo() function into this

var timesTwo = function(number) {
    return number * 2;
};

You need to return the value from the function, and goal is to return the value multiplied by two.


#3

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

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

This is what I get but it still gives me an error.
"Console.log is not a function"


#4

This often happens when you use console.log = (value) instead of console.log(value) because by using the assignment operator = you overwrite console.log with a new value and that value might not even be a function. So to solve this you just need to refresh the page, that will reload the javaScript and reset console.log back to its default value.


#5

There you go.

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

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