参数未加在一起

时间:2019-01-20 02:05:46

标签: javascript

//已解决

我正在尝试将参数加在一起,然后将其除以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.


1 个答案:

答案 0 :(得分:1)

更改

area = Math.sqrt(perimeter * ((perimeter - a) * (perimeter - b) * (perimeter = c)));

area = Math.sqrt(perimeter * ((perimeter - a) * (perimeter - b) * (perimeter - c)));