Skip to content

Commit 02942eb

Browse files
authored
Alternative solution
1 parent 13be80a commit 02942eb

File tree

1 file changed

+16
-0
lines changed
  • 1-js/05-data-types/10-date/7-get-seconds-to-tomorrow

1 file changed

+16
-0
lines changed

1-js/05-data-types/10-date/7-get-seconds-to-tomorrow/solution.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,19 @@ function getSecondsToTomorrow() {
1313
return Math.round(diff / 1000); // convert to seconds
1414
}
1515
```
16+
17+
Alternative solution:
18+
19+
```js run
20+
function getSecondsToTomorrow() {
21+
let now = new Date();
22+
let hour = now.getHours();
23+
let minutes = now.getMinutes();
24+
let seconds = now.getSeconds();
25+
let totalSecondsToday = (hour * 60 + minutes) * 60 + seconds;
26+
let totalSecondsInADay = 86400;
27+
28+
return totalSecondsInADay - totalSecondsToday;
29+
}
30+
31+
```

0 commit comments

Comments
 (0)