计算JavaScript中直角三角形的斜边
我们需要编写一个包含两个数字的JavaScript函数。第一个数字代表直角三角形底边的长度,第二个数字垂直。然后,该函数应根据这些值计算斜边的长度。
例如-
如果基=8,垂直=6
然后输出应该是10
示例
以下是代码-
const base = 8;
const perpendicular = 6;
const findHypotenuse = (base, perpendicular) => {
const bSquare = base ** 2;
const pSquare = perpendicular ** 2;
const sum = bSquare + pSquare;
const hypotenuse = Math.sqrt(sum);
return hypotenuse;
};
console.log(findHypotenuse(base, perpendicular));
console.log(findHypotenuse(34, 56));输出结果
以下是控制台上的输出-
10 65.5133574166368
热门推荐
10 感谢韩语老师祝福语简短
11 升职文案高级祝福语简短
12 花童结婚祝福语大全简短
13 向国庆送祝福语简短
14 什么寄语简短祝福语女生
15 客户回礼祝福语大全简短
16 女孩生日祝福语简短创意
17 家长回复节日祝福语简短
18 给外婆敬酒祝福语简短