
做一道数学题,如何利用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,我们会在看到邮件的第一时间内为您处理!

码云(gitee)提交不显示贡献度解决方法
HTTP协议中请求头和响应头的常用字段有哪些?
环球巴士是什么,环球巴士官方合租操作流程