
做一道数学题,如何利用js计算圆柱体的体积,下面web建站小编给大家详细介绍一下实现代码!
计算圆柱体的体积:
function cylinderCount(height, diameter) {
this.height = height;
this.diameter = diameter;
}
cylinderCount.prototype.Volume = function () {
var radius = this.diameter / 2;
return this.height * Math.PI * radius * radius;
};
var cyl = new cylinderCount(7, 4);
console.log('圆柱体积:', cyl.Volume());
//圆柱体积: 87.96459430051421
//保留2位小数点
console.log('圆柱体积:', cyl.Volume().toFixed(2));
//圆柱体积: 87.96
上面是“数学题:利用js计算圆柱体的体积”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3111.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

mysql怎么查询数据库表中指定行数据
星明天文台:一个专门进行各类小行星、彗星、变星等天体的搜索发现平台
Baichuan-M3:百川智能开源医疗大模型,刷新医疗AI评测全球纪录