From b35aa9625a7146a5ae439e850814a17603b8a473 Mon Sep 17 00:00:00 2001 From: Abdulkader Date: Sat, 11 Apr 2026 04:00:00 +0800 Subject: [PATCH] Correction: 38-round-trip.js Replaced the addition of `24` if the `flightTime` is below zero, with math absolute function, since it's the correct way to handle the negative value of the difference. --- 7-objects/38-round-trip.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/7-objects/38-round-trip.js b/7-objects/38-round-trip.js index 16cf93e..3998eb9 100644 --- a/7-objects/38-round-trip.js +++ b/7-objects/38-round-trip.js @@ -17,10 +17,7 @@ const departTripTicket = { leaveTime: 12, arriveTime: 23, flightTime() { - let flightTime = this.arriveTime - this.leaveTime; - if (flightTime < 0) { - flightTime += 24; - } + let flightTime = Math.abs(this.arriveTime - this.leaveTime); console.log(flightTime + " hours"); } }; @@ -41,10 +38,7 @@ const returnTripTicket = { leaveTime: 24, arriveTime: 4, flightTime() { - let flightTime = this.arriveTime - this.leaveTime; - if (flightTime < 0) { - flightTime += 24; - } + let flightTime = Math.abs(this.arriveTime - this.leaveTime); console.log(flightTime + " hours"); } };