Answer is Wrong? Functions with Two Parameters


Hello. The exercise gets a "pass", but I don't understand the answer appearing in the console. It shows 28. Shouldn't it be 20? Can someone explain why 28 is correct?

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


Hello @truckintortuga,

It seems you have passed four arguments where only 2 should be passed

perimeterBox(7, 3);

This should fix your code...


Thanks for responding. It told me I got the code correct and showed 28. Does this mean the exercise has a bug in it?


No, @truckintortuga,

That just means that it takes the first two arguments, since that is what you have specified, in this case being 7 and 7. So, your function perimeterBox(7,7,3,3) is equivalent to just perimeterBox(7, 7) And that is why it returns 28.


Ok, if it is seeing it as perimeterBox(7,7). Shouldn't it be adding 7 + 7 to return 14? Why 28?


Because your function returns length + length + width + width, so in this case length = 7 and width = 7 so it returns 7 + 7 + 7 + 7 which is 28...


Ah, got it. I understand both of my confusions. I'm so glad I asked, instead of ignored it. Thanks so much!!!


No worries. Keep coding hard!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.