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

如何利用CommonJS实现模块化编程
牛面AI:简历押题、综合面试、专项面试和面试报告等功能的AI面试工具
I2V-01-Director:海螺AI推出的一款AI视频生成模型,开启AI视频生成的电影级时代