计算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 送给学长毕业祝福语简短