Want greeting function to work: 5/13


#1

var greeting = function (name) {
var greeting = "hi how are ya";
console.log(greeting);
};

greeting("pally" +" "+name)

when I run this, the console just says "hi how are ya" instead of "pally hi how are ya" like i want it to

anybody know how to make it work?


#2

Well, to print that, you have to do

console.log("pally" + " " + greeting);


#3

First of all it's not necessarily a good idea to use the name of the function as a variable name in the function itself, just pick a different name the syntax is ok. The problem is that you do no use your name parameter. The idea is that name (the variable in the function) gets it's value form the function call so in your case "pally "+name. But name is not defined outside the function so the use of name here probably gives you an error. If you want to write "pally hi how are ya" you would e.g. use:

var greeting = function (name) {
    var message = name+"hi how are ya";
    console.log(message);
};

greeting("pally" +" ")

Now name would have a value of "pally " and you can use name inside the function in the same way you would use "pally ".


#4

oh yea I thought there was something redundant and strange with what I was doing.

i ran that though and the console just says [Function] it didn't actually print out the message

i need to play around more with the different components of a function

var blaBla= function(someParameter)
var someOtherParameter= something lalala
//do some stuff here;
};

i'm starting to get it, but also still trying to see how all the pieces of functions work together and stand in for each other. One thing that doesn't make sense to me is that the parameter you give the function turns orange, but then in the {} of the function, its not orange anymore, so it makes me wonder if the computer is seeing those as the same


#5

The [Function] is often caused by console.log(functionName) in this case it just tells you that this is a Function. If you instaed of this use console.log(""+functionName) it even gives you a stringified version of the function. For the orange parameters yes they are treated as the same although they might have different colors.