19. More Kinds of Methods


#1

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();

console.log(square)

Thank you for your answer :).


#2

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

what exactly is your question?


#3

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


#4

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)


#5

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


#6

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


#7

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


#8

that is good, right? Any further questions?


#9

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


#10

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