Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用长度和宽度Javascript返回矩形的面积_Javascript_Function - Fatal编程技术网

如何使用长度和宽度Javascript返回矩形的面积

如何使用长度和宽度Javascript返回矩形的面积,javascript,function,Javascript,Function,矩形的面积等于长度*宽度。我们只需传递两个参数并返回它们的乘法:) 试试这个: function getRectangleArea(length, width) { //return the area of the rectangle by using length and width // code here } 也许,在长度和宽度上增加一点控制不是个坏主意 function getRectangleArea(length, width) { return length*width;

矩形的面积等于
长度*宽度
。我们只需传递两个参数并返回它们的乘法:)

试试这个:

function getRectangleArea(length, width) {
 //return the area of the rectangle by using length and width
 // code here
}

也许,在长度和宽度上增加一点控制不是个坏主意

function getRectangleArea(length, width) {
  return length*width;
}

let area = getRectangleArea(4,5);

console.log(area);

@NoobProgrammer你也可以在自己的操场上尝试一些东西

这可能会有所帮助:。如果您有一个关于如何在JavaScript中实现的具体问题,请询问。但你必须至少尝试一些东西,而不仅仅是让别人帮你实现。有什么想法吗?返回length*width,但按照指令console.log将不起作用?我没有得到它:)你在寻找其他东西吗:)如果你运行上面的代码,你会得到你想要的结果。只是你必须通过两个数字。
function isNumber(value){
  if (typeof value === 'number') return true;
  else return false;  
} 

function getRectangleArea(length, width) {
    if(isNumber(length) && isNumber(width)) {
        return length*width;
    }
 }

let area = getRectangleArea(14.6,5.1);

console.log(area);