ปัญหา
เราจำเป็นต้องเขียนฟังก์ชัน 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