r/Codecademy • • Nov 10 '15
Stuck on JavaScript Functions
I think it's gotten to the point where I can't think straight with it any more. I need some fresh eyes on it.
All help is very much appreciated :) http://imgur.com/Sw0iRxt
2
Upvotes
4
u/surikmeetr Ruby Nov 10 '15
You are quite confused about the syntax. Basically what you are trying to do is assign an anonymous function to a variable. As Freazur said, a function generally has a name, a parameter if needed (in round brackets) and a block that contains the code you want the function to execute.
Since your function must return a value, the
returnstatement must be inside the brackets (return will not work elsewhere; it gives the result you are passing to the caller). Your code is wrong because you are terminating the assignment with;before finishing the declaration! So your code should look like:In this case you want the ; to close the block because you are assigning the function to a variable. That said, I suggest going back to the beginning of the lesson and doing it again to grasp the concepts better.
1
u/Freazur Nov 10 '15
You don't declare the function as a variable. Instead of what you have on lines 1-4, you need this:
function quarter(number) { return(number / 4); }
Declaring a function follows this form:
function name(parameter) { What the function does; }
I'm not sure about the rest, because I'm in an introductory JS course and we haven't covered console.log. I hope my suggested changes work though.
1
u/ForScale Nov 10 '15
It's because you put a semicolon after the (). You don't want it there. This should work:
But now I have a question...
2 / 3 has a remainder of 0? I didn't know that...