Visitar URL original
Change to toggle function instead of add/remove functions · wesbos/JavaScript30@3b71ac4 · GitHub
Skip to content

Commit 3b71ac4

Browse files
committed
Change to toggle function instead of add/remove functions
1 parent 9142494 commit 3b71ac4

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

  • 02 - JS + CSS Clock - Complete

‎02 - JS + CSS Clock - Complete/main.js‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,22 @@ function setDate () {
77

88
var seconds = now.getSeconds()
99
var secondsDegrees = ((seconds / 60) * 360) + 90
10-
if (secondsDegrees === 90) removeTransition(secondHand)
11-
else if (secondsDegrees === 96) addTransition(secondHand)
10+
if (secondsDegrees === 90 || secondsDegrees === 96) toggleTransition(secondHand)
1211
secondHand.style.transform = `rotate(${secondsDegrees}deg)`
1312

1413
var mins = now.getMinutes()
1514
var minsDegrees = ((mins / 60) * 360) + 90
16-
if (minsDegrees === 90) removeTransition(minHand)
17-
else if (minsDegrees === 96) addTransition(minHand)
15+
if (minsDegrees === 90 || minsDegrees === 96) toggleTransition(minHand)
1816
minHand.style.transform = `rotate(${minsDegrees}deg)`
1917

2018
var hours = now.getHours()
2119
var hoursDegrees = ((hours / 12) * 360) + 90
22-
if (hoursDegrees === 90) removeTransition(hourHand)
23-
else if (hoursDegrees === 120) addTransition(hourHand)
20+
if (hoursDegrees === 90 || hoursDegrees === 120) toggleTransition(hourHand)
2421
hourHand.style.transform = `rotate(${hoursDegrees}deg)`
2522
}
2623

27-
function removeTransition (el) {
28-
el.classList.add('no-transition')
29-
}
30-
31-
function addTransition (el) {
32-
el.classList.remove('no-transition')
24+
function toggleTransition (el) {
25+
el.classList.toggle('no-transition')
3326
}
3427

3528
setInterval(setDate, 1000)

0 commit comments

Comments
 (0)