如何使用长度和宽度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);