3
06/11/2024 8:51 am
Inicio del tema
I have to write a JS (JavaScript) function that calculates the area of the figure (see the image below) by given values for w, h, W and H. The lower right corner is always common for the two rectangles.

The input comes as four number parameters w, h, W and H.
Examples:
Input:
2, 4, 5, 3
Output:
17
Input 2:
13, 2, 5, 8
Output 2:
56
The output should be returned as a result of your function.
1 respuesta
2
06/11/2024 8:52 am
Here is the code and the solution:
function figureArea(w, h, W, H) {
var s1 = w * h;
var s2 = W * H;
var s3 = Math.min(w, W) * Math.min(h, H);
//let [s1,s2,s3]=[w * h, W * H, Math.min(w, W) * Math.min(h, H)];
console.log(s1 + s2 - s3);
}
figureArea(13, 2, 5, 8);
