Intro to objects I - Why isnt this working


#1


Introduction to Objects I : 24. Constructors With Methods


syntax error: unexpected end of input


function Rectangle(height, width) {
  this.height = height;
  this.width = width;
  this.calcArea = function() {
      return this.height * this.width;
  };
  // put our perimeter function here!
  this.calcPerimeter = function() {
      return 2 * this.height + 2 * this.width;
}

var rex = new Rectangle(7,3);
var area = rex.calcArea();
var perimeter = rex.calcPerimeter();


#2

You are missing a closing bracket.

    Your brackets are as follows:
  1. You opened the function Rectangle

  2. You opened the function calcArea

  3. You closed calcArea

  4. You opened the function calcPerimeter

  5. You closed calc perimeter


#3

I advise you a change in the bracing braces.
Then you can not make such a mistake happen

Like this:

function Rectangle(height, width) 
{
  this.height = height;
  this.width = width;
  this.calcArea = function() 
  {
      return this.height * this.width;
  };
  // put our perimeter function here!
  this.calcPerimeter = function() 
  {
      return 2 * this.height + 2 * this.width;
  };

Now you can easily see where it is missing


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.