How to use direct formulae In Javascript
In this Scenario, we will create a function that will hold the formula by taking edge of a cube (a) as a parameter. The function proceeds to calculate the Volume of the Cube using the formula (a * a * a). The calculated Volume is returned as the result of the function.
Syntax:
function volCube(a) {
return a * a * a;
}
Example: Below is the function to find Volume of Cube using the general formulae:
function volCube(a) {
return a * a * a;
}
let a = 5;
console.log('Volume = '+volCube(a));
Output:
Volume = 125
JavaScript Program to Find Volume of a Cube
A Cube is a 3-dimensional box-like figure represented in the 3-dimensional plane that has six-shaped faces. It has length, width and height of the same dimension.
The Volume (V) of a Cube can be calculated using the given formula: Volume(V) = a * a * a
Where, a is the Edge of the Cube.
Example:
Input : 10
Output : Volume = 1000
Input : 5
Output : Volume = 125
Table of Content
- Using direct formulae
- Using Math.pow() function
- Using Exponentiation Operator
- Using ES6 arrow function