How to calculate the area of a pentagon in JavaScript

2 Answers

0 votes
function pentagon_area(side, apothem) {
    return 5.0 * (side * apothem) / 2.0;
}

const side = 5.0;
const apothem = 3.0;

const area = pentagon_area(side, apothem);

console.log(`Area = ${area.toFixed(2)}`);



/*
run:

Area = 37.50

*/

 



answered Jul 12, 2021 by avibootz
edited 8 hours ago by avibootz
0 votes
function area_regular_pentagon(side) {
    return (1 / 4) * Math.sqrt(5 * (5 + 2 * Math.sqrt(5))) * (side ** 2);
}

console.log(area_regular_pentagon(7));


/*
run:

84.30339262885938

*/

 



answered 3 hours ago by avibootz
...