19. More Kinds of Methods


I tried to find out, why are there "var p, and var a"?

ar square = new Object();
square.sideLength = 6;
square.calcPerimeter = function() {
  return this.sideLength * 4;
// help us define an area method here
square.calcArea = function() {
    return this.sideLength * this.sideLength;
var p = square.calcPerimeter();
var a = square.calcArea();


Thank you for your answer :).


they are variable to store the result of calling calcPerimeter and calcArea on your square object.

what exactly is your question?


if delete var p and var a, I get the solution, so why we have to put it in the code?


because you want to store the result in variables? If you want, you can simply then log the variables to the console to display the result (result doesn't always have to be displayed, sometimes you just want to store it)


so you mean, if I would console.log(p, a) I will get the solution.


what do you mean by solution? Yes, this will log whatever is stored in the variable p and a to the console


sry not solution. The display shows me the value of area and perimeter.


that is good, right? Any further questions?


not yet :wink:. thx. I will go further with the excercises...


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