//已解决
我正在尝试将参数加在一起,然后将其除以2,以便将结果传递给sqrt方法。经过一番排解,我发现它只是返回函数的最后一个参数。
typeOf返回参数是数字,所以我不确定发生了什么。
function areaTriangle(a,b,c) {
let area, perimeter;
perimeter = (a + b + c)/2;
//heron's formula
area = Math.sqrt(perimeter * ((perimeter - a) * (perimeter - b) * (perimeter = c)));
return area;
}
//areaTriangle(3,3,9) perimeter returns 9(arg of c). Should be 7.5.
答案 0 :(得分:1)
更改
area = Math.sqrt(perimeter * ((perimeter - a) * (perimeter - b) * (perimeter = c)));
到
area = Math.sqrt(perimeter * ((perimeter - a) * (perimeter - b) * (perimeter - c)));