Open In App

JavaScript Program to Find Surface Area of a Cone

Last Updated : 12 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Mathematically, the Surface area of the Cone can be calculated using the formula: area = pi * r * s + pi * r^2, Where r is the radius of the circular base, and s is the slant height of the cone. We will calculate the Surface Area of a Cone programmatically using JavaScript.

These are the following methods:

Using Destructuring Assignment and Spread Operator

In this approach, we are using the destructuring assignment and the spread operator to encapsulate the sum of the squares of radius and height within an array, allowing Math.sqrt to extract the value for calculating the surface area of the cone.

Syntax:

let [, value] = [...[expression]];

Example: The below uses Destructuring Assignment and Spread Operator to find the Surface area of a Cone.

Javascript
let r = 5;
let h = 10;
let res = Math.PI * r * (r + Math.sqrt([...[r*r + h*h]]));
console.log(res.toFixed(2));

Output
254.16

Using Arithmetic Operations

In this approach, we calculate the surface area of a cone using basic arithmetic operations. The formula 3.1415 * r * (r + √(r² + h²)) is used, providing the result with two decimal places using toFixed().

Example: The below uses Arithmetic Operations to find the Surface area of a Cone.

Javascript
let r = 5;
let h = 10;
let res = 3.1415 * r * (r + (r*r + h*h)**0.5);
console.log(res.toFixed(2));

Output
254.15

Using Math.pow

In this approach, we are using the Math.pow function for exponentiation, applying it to the expression (r * r + h * h) to find the square root. The calculated result is then used in the formula π * r * (r + √(r² + h²)), with the final surface area displayed with two decimal places using toFixed.

Syntax:

Math.pow(base, exponent);

Example: The below uses Math.pow to find the Surface area of a Cone.

Javascript
let r = 5;
let h = 10;
let res = Math.PI * r * (r + Math.pow((r * r + h * h), 0.5));
console.log(res.toFixed(2));

Output
254.16

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads