+ 2
why is this code giving the answer 1
class Point{ constractor(x,y) { this.x = x; this.y = y; } static slopeAB (A, B) { const dx = A.x-B.x; const dy = A.y-B.y; return dy/dx; } } const P1= new Point(1,2); const P2 = new Point(3,4); console.log(Point.slopeAB(P1,P2));
3 Antworten
+ 1
A.x = 1, B.x = 3
dx = A.x - B.x means 1 - 3 yields -2
A.y = 2, B.y = 4
dy = A..y - B.y means 2 - 4 yields -2
slopeAB() returns <dy> (-2) divided by <dx> (-2) which yields 1.
+ 1
dx=3-1=2
dy=4-2=2
2/2=1
+ 1
Thanks 👍