Finding the length of the diagonal of a cuboid using JavaScript

JavascriptWeb DevelopmentFront End Technology

Problem

We are required to write a JavaScript function that takes in the length, width and height of a cuboid and return the length of its diagonal.

Example

Following is the code −

 Live Demo

const height = 10;
const width = 12;
const length = 15;
const findDiagonal = (l, w, h) => {
   const ll = l * 2;
   const ww = w * 2;
   const hh = h * 2;
   const sum = ll + ww + hh;
   const diagonal = Math.sqrt(sum);
   return diagonal;
};
console.log(findDiagonal(length, width, height));

Output

8.602325267042627
raja
Published on 19-Apr-2021 11:03:52
Advertisements