![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Finding the length of the diagonal of a cuboid using JavaScript
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 −
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
Advertisements