Stuck on Intro to Functions Ex #7: Return Keyword - SOLVED


#1

I understand that the return keyword will give back the value without printing. I am just really stuck on the exercise itself.
This is my code below. The error keeps telling me that I haven't called the New Number. Between console.log and my very last line - newNumber(3);
What am I doing wrong?

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

timesTwo(4); // Call timesTwo here!
var newNumber = function(timesTwo) {
var val=(newNumber * 3);
console.log(val);
};
newNumber(3);


#2

Are you sure you are on exercise 7? When i reset the code this is what i get:

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

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

Ah, i think i get it. All you need to do, is call the function. You created an additional function. To call a function, simple use the function name with brackets: timesTwo(), in this case the function also requires an argument, give it any number between the brackets: timesTwo(2), that is all you need to do on line 7


#3

I believe that the actual error was:

"You didn't call the timesTwo function!"


#5

I just figured it out. I was over-thinking it.
You literally have to follow the instructions. They are looking for code in Lines 7 and 8 and nothing more.
Thank you, stetim94, for your help. It was exactly as you said.
(The hint in helpful here.)


#6

You where a bit overthinking, but good to hear you resolved the issue, you understand it?


#7

That's a really fair question. Here's my thinking:
You "call the function" after you right the lines of code. After the }; (so very last line). That's what makes the rest of it work.

I was confused by the direction to "call the function" when I felt I was starting a new function. That was how I thought you needed to incorporate the return keyword used at the start of the lesson.

I felt confident about the glossary of terms and the concepts but for some reason I was a bit cooky with function (global, local, etc). Will continue to work hard at it. Thank you!


#8

Functions don't do anything unless you call them. Functions are such a beautiful thing), the function you have here can serve as an excellent example:

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

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

but if for some reason you need to multiply a number with two, you can simple add/make another function call, store it in a variable and print it to the console:

var anotherFunctioncall = timesTwo(12)
console.log(anotherFunctioncall)

#9

It said the same thing to me. i did it over and it still said it. can u try to help me


#10

#11

go here, make a new topic, fill in the template so we have all the information needed you to help you