Functions with two parameters

#1

Hello,

This code returns correctly, however it’s not what the computer is looking for… What am I missing?

Thanks!

var perimeterBox = function(number1, number2, number3, number4) {
var length = (number1 + number2);
var width = (number3 + number4);

return length + width;
}
perimeterBox (2,1,9,1);

#2

I think it’s expecting you to only put in two numbers into your function and then returning the perimeter of the lengths provided:

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

#3

If you don’t understand why this works, or what the lesson was asking I can clarify. Just let me know.

#4

Math simplification:

``````length + length + width + width   =>

2 * length + 2 * width            =>

2 * (length + width)
``````

Simplifying our math simplifies our code.

#5

Cool, that looks great!

I guess I was confusing ‘variable’ with perimeter. Also, I was over thinking, with this code if the rectangle has odd shaped sides it wouldn’t work but I guess that’s a little out of the box.

thank you!

#6

I was going to mention that there is no four sided polygon can have the dimensions, `2,1,9,1`. A rectangle by definition has only two dimensions.