Functions with two parameters



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


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

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


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;


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


Math simplification:

length + length + width + width   =>

2 * length + 2 * width            =>

2 * (length + width)

Simplifying our math simplifies our code.


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!


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.