Jump to content

Is My Constructor Correct


rissa146
 Share

Recommended Posts

Create a Shape constructor function that has a height and width property. Include a method that will calculate the area of the shape, where area is defined as the shape's height multiplied by its width.



function shapeFunct(x,y){
this.height = x;
this.width = y;
return x * y;
}

// call the function shapeFunct(100,100);

Link to comment
Share on other sites

That's not a constructor yet, that's a function. Do you know what a constructor is? And what a method is?

You need to go back through your course material and read about constructors and methods.

 

Here's the W3Schools page on the matter: http://www.w3schools.com/js/js_object_prototypes.asp

 

However, I recommend you go back to learn the basics before attempting object-oriented programming. Even then, if you've never learned object-oriented programming before, Javascript is not the best language to learn it from. Javascript's version of "object-oriented" programming is very weird and does not match the actual theory of object-oriented programming.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...