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

5th Dec 2021, 4:18 PM
Steve Nova
Steve Nova - avatar
3 ответов
+ 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.
5th Dec 2021, 9:24 PM
Ipang
+ 1
dx=3-1=2 dy=4-2=2 2/2=1
5th Dec 2021, 4:26 PM
Jayakrishna 🇮🇳
+ 1
Thanks 👍
6th Dec 2021, 2:54 AM
Steve Nova
Steve Nova - avatar