9) Functions with new parameters


#1



enter link description here


// Write your function starting on line 3

var perimeterBox = function (length,width) {
var perimeter = length + length + width + width
console.log(perimeter)
}
perimeterBox(6,2)


Replace this line with your code.


#2

what is wrong?
Please help me


#3

@ipohzw,

The instruction.....
01. Write a function called perimeterBox that returns the perimeter of a rectangle.
( you are using the console.log() )


#4

@ipohzw,

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 ) );

How does a function work?
#5

Thank You! it Really helped


#6

but ...
// Write your function starting on line 3

var perimeterBox = function (length,width) {
var perimeter = length + length + width + width
return perimeter
}
console.log(perimeterBox)

still does not work...


#7

@ipohzw
because if you want to =call= the perimeter function
you will have to
use a pair of parentheses-( )
and provide 2 ARGUMENTS


#8

Then what are the two main arguements?


#9

@ipohzw,
maybe a 6 an 2 ???
Please read the function talk again....and again....untill you grasp what PARAMETER and ARGUMENTS are.....


#10

what is this? I do not understand


#11

What is a function talk?


#12

Oh sorry. Thank you for your patience and understanding. i leant a lot through this


#13

@ipohzw,
function talk is https://discuss.codecademy.com/t/9-functions-with-new-parameters/32940/4?u=leonhard.wettengmx.n


#14

I got the hang of it


#15

Thanks! thanks so much


#16

I don't understood... This is my code:

var perimetrBox = function (length, width) {
return length + length + width + width;
};
perimetrBox(4,7);

What's wrong ?


#17

Hi you wrote

var perimetrBox

Instead of

var perimeterBox

#18

var perimeterBox = function (length,width) {
var perimeter = length + length + width + width
return(perimeter)
}
perimeterBox(6,2)

This is the correct code, you have said that you want to return length + length + width + width in your code, but the instructions ask that you return(perimeter) not length + length + width + width. You define your perimeter with the length + length + width + width. Hope this helps!