# Thread: Creating a sumAreas() class with JS?

1. ## Creating a sumAreas() class with JS?

I am currently doing a small test, but I am having trouble understanding what this question is asking me to do.

a. Produce an object to represent a circle. Your circle object must implement two instance methods getCircumference() and getArea(). These methods will return the circumference and area of the circle respectively. The object should also include a class method sumAreas(), which takes two radii as parameters and returns the sum of their two areas.
I've seen an article on Sitepoint that uses getCircumfrance and getArea;

Code:
```	function Circle(radius){

this.getArea = function(){
}

this.getCircumference = function(){
var circumference = diameter*3.14;
return circumference;
}
}

var bigCircle = new Circle(100);

But what does it mean by the last sentence, and a setAreas() class?

The object should also include a class method sumAreas(), which takes two radii as parameters and returns the sum of their two areas.
How do I do this?

2. The question has nothing to do with native javascript functions. The question is asking you to create an object, and then create three functions yourself for that object:

getCircumference(), getArea()

which are typical 'get' functions that don't do any calculations themselves, and instead just retrieve values from the object, as well as

sumAreas()

which has two parameters and returns the result of a mathematical calculation involving the two parameters.

Here is a beginning article on how to create objects in javascript:

http://www.sitepoint.com/article/oriented-programming-1
http://www.sitepoint.com/article/oriented-programming-2

But what does it mean by the last sentence, and a setAreas() class?
It doesn't quite say that--it says a "class method setAreas()". In object orientated programming 'speak', objects are called 'classes', and object properties that are values (as opposed to functions) are called 'members' while object properties that are functions are called 'methods'. So, all the above statement is saying is that you are supposed to create a third function for the object.

3. Yes, I was confused. I was confused on whether it was asking for a function or a class, or something else.

Regardless, I want to thank you for your help with this matter and I will research the links you've provided.

4. This is right, isn't it?

Code:
```	function Circle(radius){

/* #################### */

this.getArea = function(){
}

/* #################### */

this.getCircumference = function(){
var circumference 	= diameter*3.14;
return circumference;
}
}

}```

5. Originally Posted by worchyld
The object should also include a class method sumAreas(), which takes two radii as parameters and returns the sum of their two areas.
The keyword is "class method". Class (aka static) method, as opposed to "ordinary" member, applies to the class, not to particular class instance i.e. object. The term "class method" isn't 100% correct in javascript because there are no "classes" in this language, but the same can be done by assigning something to object's constructor.

Code:
```// define constructor

// define ordinary member function
Circle.prototype.getArea = function() ...

// define "class" or "static" function

Circle.sumAreas = function() ...```
and this is how they are called
Code:
```// constuctor
someObject = new Circle();

// member function
someObject.getArea()

// static function
Circle.sumAreas();```

6. Ah, looks like I'm out of my depth with that question - I've attempted it, and that's all anybody can ask anybody to do.....

Thanks.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•