使用 JavaScript 找出长方体的对角线长度
问题
我们需要编写一个 JavaScript 函数,该函数接收长方体的长度、宽度和高度,并返回其对角线的长度。
示例
以下是代码 −
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));输出
8.602325267042627
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP