Meet the Functions Q&A


#1

I am correcting the badly written function and it says that I have succesfully corrected it. That should be fine shouldn't it? Well, it's not... in my opinion. It still looks very strange, I repeat, in my opinion. :warning: Here's the javascript:

// Nicely written function:
var calculate = function (number) {
    var val = number * 10;
    console.log(val);
};

// Badly written function with syntax errors!

var greeting = function (name) {  
    console.log(name);
};

greeting("camillita")

So please tell me if my suspicions are correct.


#2

There's nothing strange about the function - greeting that you have placed in the forum.
Please explain why you think its strange


#3

Hi dondabreraozemail_co*,
Well, I just thought it looked funny compared to the first one. It looked like it was missing something. To be more precise, I thought it was missing the var val = function (number) { or in other words, the thing I don't understand one jot about. Could you tell me what it means? Or is there something I missed?

*your username reminds me of Brazil :wink:


#4

What don't you understand?

var calculate = function (number) {

or this:

 var val = number * 10;

because your example was a mixture of both.

The first is a function stored in a variable named calculate. That has one parameter meaning you can pass one value to this function by using calculate(10). This calls the function and inside of the function you can use the parameter variable as if it was the value that you passed.

The second is just an intermediate varaible, you calculate your score and save it for later, in this case for printing it on the next line.


#5

No, in your original post, you had two separate discrete functions. Entirely separate from each other.
I can spend the entire night explaining this :smile:
However, do yourself a favour and read up about functions on the internet. There's plenty of great examples.
But if you want to narrow down to what you don't understand, I'll certainly help you.
So feel free to ask me explicit questions. At the moment, you're asking a very broad question that would take a long time to explain.
Yep, my ancestors are Portuguese and Spanish and a mix of Dutch and French too.