使用 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