Calling the greeting function?


#1

// Below is the greeting function!
// See line 7
// We can join strings together using the plus sign (+)
// See the hint for more details about how this works.

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

// On line 11, call the greeting function!
var greeting = function(Peter) {
console.log("Hello" + " " + "Peter");
}cks above>


#2

If you're trying to call it:

greeting("Peter");

you already have greeting setup so all you need to do is pass in a value for name, which you want to pass in your name so

"Peter" would be your name value, pass it in => greeting("Peter");


#3

Oh my god. Thank you randonuser.


#4

How about this one: Trying to find the cost of 5 oranges.

var orangeCost = function (number); {
var price = 5.00 * 5;
console.log(price);
}
orangeCost(25)


#5

I'll try to explain functions.

var getCost = function(number_of_items) {
        var item_price = 2.50;
        var cost = item_price * number_of_items;
        return cost;
    };

With the above, we wrote a function called "getCost". This function, "getCost", has 1 parameter "number_of_items".
If I have 3 items, I need to pass in a value of 3 to getCost.

e.g.,

var cost_of_3_oranges = getCost(3);
var cost_of_5_oranges = getCost(5);

What happens in real time:

Create variable cost_of_3_oranges.
Look at variable "getCost", realize it is a function with 1 parameter "number_of_items".
[ //    bracket scope = getCost function
    number_of_items = 3
    create item_price variable with value of 2.5
    create cost variable with value of item_price multiplied by number_of_items.
    - number_of_items = 3, i know this from the passed in value of 3
    - item_price = 2.5, i know this since i declared it to be 2.5 within the function     
    - cost = 2.5 * 3  => 7.5
     return cost out of function.
]
set variable cost_of_3_oranges to be equal to the result from the function getCost with parameter "number_of_items" value of 3.

cost_of_3_oranges is now equal to 7.5

I hope this has helped clear the air around functions.


#6

Some of this, obviously, is beyond me, but I thank you.


#7

var greeting = function (name) {
var func = "name";
console.log (func);
greeting('hi')
}


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.