Question:

Create a Circle() constructor function to make circle objects with an area method. Add a private PI variable to the circle objects that are created a set its value equal to 3.14.

 

Answer:

function Circle(radius) {
  var PI = 3.14;
  this.radius = radius;
  this.area = function () { return PI * Math.pow(this.radius, 2) };
}

var my_circle = new Circle(5);
console.log(my_circle.area());

Keywords:

© 2017 QuizBucket.org