Help 5. Functions


Can anyone help me with this function? I don't know whats incorrect.? I have to call the greetings function

This was the badly written function and I have to "fix" it:

// Badly written function with syntax errors!

greeting var func{name}(console.log(name)))}

This was my idea but it doesn't work:

var greeting = function (name) {
greeting = ("Elias")


you allmost got it.

change it to:


@puristaja Great, thank you!!


please help me someone, where is error, it says syntax error

var greeting = function (name); {
console.log("Great to see you," + " " + name);

var greeting = function("name");


What comes in the () after function here:

var greeting = function("name");

is called parameter and is supposed to be a name of a local variable to the function. So as it is supposed to be a variable there must not be "" around it, because "" would make it become a string (value). The way it gets it's value is by value, called argument, you pass to the function by the function call:


So both things together act like this:

    var greeting = function (name){
    greeting("anjali"); -> "Great to see you, anjali"
    greeting("arccoder77240"); -> "Great to see you, arccoder77240"

would do the same as:

    var greeting = function (name){
        var name = "anjali";
    greeting(); -> "Great to see you, anjali"
    greeting(); -> "Great to see you, anjali"

The huge difference is that the value in the second version is static meaning no matter how often you call greeting you'll always get the same result. On the other hand in the first version you pass the value to the function so you can use the exact same function to print whatever name you like just by changing the input value.

Also why do you have 2 versions of the greeting function one is sufficient. And of course no semicolons here:

function (name); {

the {} for functions are mandatory and the semicolon sort of splits these two part that should be together.

1 Function
no semicolon in the structure
no "" around the parameter
and take the console message from the first function as it seems to be more interesting than just name :slightly_smiling:


Thank you, this post was very helpful.


Cheers! it was really helfpul!