# Don't Repeat Yourself (D.R.Y)

#1

You are a creature of habit. Every week you buy 5 oranges. But orange prices keep changing!

You want to declare a function that calculates the cost of buying 5 oranges.
You then want to calculate the cost of the 5 all together.
Write a function that does this called orangeCost().
It should take a parameter that is the cost of an orange, and multiply it by 5.
It should log the result of the multiplication to the console.
Call the function where oranges each cost 5 dollars.

what i did was:

var orangeCost = function(price)
{
var price = price *5
}
orangeCost("price");

when I click save and submit it does not say it is wrong. I'm confused with this. I think something is incorrect here. can anyone help me at this

``````var orangeCost = function(price)
{
var price = price *5
}
orangeCost("price");``````

#2

### the FUNCTION talk

``````var myFunc = function( param1, param2) {
//Begin of  anonymous FUNCTION-BODY
//VARIABLE -myFunc- has an -anonymous function- assigned
//this -anonymous function- has 2 PARAMETERS param1 and param2
//param1 and param2 PARAMETERS are used
//as -local- VARIABLES throughout the FUNCTION-BODY

console.log( param1 + " and " + param2 ) ;

//End of anonymous FUNCTION-BODY
};``````

If you want to call/execute the anonymous function
you will have to add a pair of parentheses to the variable myFunc
like
myFunc();
As the anonymous function was defined
as having 2 parameters
you have to provide 2 arguments
in our case 2 string VALUES "Alena" and "Lauren"
like
myFunc("Alena","Lauren");

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

### function with 1 parameter using return-statement

``````var myFunction = function( param1 ) {
//Begin of FUNCTION-BODY
//myFunction =function= has 1 PARAMETER param1
//this param1 PARAMETER is used as a -local- VARIABLE
//throughout the FUNCTION-BODY

return param1;

//End of FUNCTION-BODY
};``````

you have defined a myFunction function
which takes 1 parameter param1
this param1 parameter is used
as a variable throughout the FUNCTION-BODY.

If you want to call/execute this myFunction function
and this myFunction function was defined
as having 1 parameter param1
you will have to provide 1 argument
in our case a "number VALUE" 4
myFunction( 4 );

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**

#### ============================================

As you are using the return-statement in your myFunction function
you will only get a return-value no-display.
You can however capture this return-value in a variable
and then use the console.log()-method to do a display.

``````var theResult = myFunction( 4 );
console.log( theResult );``````

OR directly

``console.log( myFunction( 4 ) );``

#3

You want to declare a function that calculates the cost of buying 5 oranges.
You then want to calculate the cost of the 5 all together. (5 * price-of-orange)

Write a function that does this called orangeCost().
`var orangeCost = function() { };`

It should take a parameter that is the cost of an orange,
`var orangeCost = function(price) { };`

and multiply it by 5.

``````var orangeCost = function(price) {
5 * price
};``````

It should log the result of the multiplication to the console. ( `use console.log()` )

``````var orangeCost = function(price) {
console.log(5 * price);
};``````

Call the function where oranges each cost 5 dollars.

``orangeCost(5);``

Function syntax