2
I’m pressing a Javascript question that asks for the distance between two points using that formula d(P1,P2) = sqrt((X1-x2)² + (Y1-Y2)²). The problem is you ask:
"Rewrite exercise 5 using objects created from a "Point" constructor function, the created point object must contain two propri- equivalent values of x and y and a function receiving another point object and returns the distance between them."
Here is my code:
function Ponto(x,y){
this.pontox = x;
this.pontoy = y;
this.calcula = function(p){
aux1 = Math.pow(Ponto.x - p.x,2);
aux2 = Math.pow(Ponto.y - p.y, 2);
result = Math.sqrt(aux1+aux2,2);
console.log(result);
}
}
ponto1 = new Ponto(0,0);
ponto2 = new Ponto(1,1);
ponto1.calcula(ponto2);
Only the code only returns NaN
, and not the result in float, as I would like. I have already tried to pass the values to float, but I didn’t get results, so how to make the function return the value in float?
I noticed a bit of confusion regarding the access of variables within the "class", in that reply the scopes of the variables and the form of access are explained.
– Pedro Sanção