I'm stuck on 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 that you ask:
"Rewrite exercise 5 using objects created from a" Point "constructor function, the created point object must contain two properties ages equivalent to the values of x and y and a function that receives another object point and returns the distance between them. "
Here's 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
, not the result in float , as I would like. I have tried to pass the values to float , but I could not get results, so how do you return the value in float ?