programming-examples/js/Object/Calculate the volume of a Cylinder.js
2019-11-15 12:59:38 +01:00

13 lines
423 B
JavaScript

function Cylinder(cyl_height, cyl_diameter) {
this.cyl_height = cyl_height;
this.cyl_diameter = cyl_diameter;
}
Cylinder.prototype.Volume = function () {
var radius = this.cyl_diameter / 2;
return this.cyl_height * Math.PI * radius * radius;
};
var cyl = new Cylinder(7, 4);
// Volume of the cylinder with four decimal places.
console.log('volume =', cyl.Volume().toFixed(4));