Functions with 2 parameters


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-6LzGd/2/1?curriculum_id=506324b3a7dffd00020bf661#


Oops, try again. It looks like your perimeterBox function doesn't return the correct perimeter (4) for a width of 1 and a length of 1.

Also, the output says:
NaN
4


var perimeterBox = function (length, width) {
    console.log((length*2) +(width*2));
};
perimeterBox(1);


#2

You need to pass second parameter!

Example..

Suppose I made a function that prints multiplication of two numbers..

var multi = function (num1 , num2) {
    console.log(num1 * num2);
}

Now we defined a function..
Now how to use our function?
To use our function.. we call it..
How to call?
We put name of function and put Exact same number of values inside it (inside the parentheses) separated by commas, that it needs.
As our example function needs two values!

multi(2,3);

It will print : 6


#3

So is this correct?

var perimeterBox = function (length, width) {
console.log((length * 2) + (width * 2));
};
perimeterBox(1,1);


#4

Try to execute by your own and tell me :slight_smile:


#5

Didn't work.
(;一_一)

Output:
4
4


#6

Oh one more thing ,instead printing things, Function can return values too..

Like printing function will be like this..

var printFunc = function() {
    console.log(print something);
};

Function can return values using return keyword..

var returnFunc = function() {
    return something;
};

Try using return instead of console.log() ?


#7

Yep, it worked. ;D
Thanks a lot!


#8

Hey I strongly suggest to read the instruction!
If you read the instruction of this exercise it mentions to return value(i.e is parameter) not print!

so do read instructions of exercise !

(from next sections):slight_smile:


#9

They want you to use return not console.log to output the sum. As such:

var perimeterBox = function (length, width) {
return length + length + width + width;
};

perimeterBox(2, 4);


#10