Skip to content

Commit 4be6f7a

Browse files
committed
Completed Lesson wesbos#2
1 parent 1b44b5b commit 4be6f7a

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

02 - JS + CSS Clock/index.html

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,43 @@
6969
</style>
7070

7171
<script>
72-
const secondHand = document.querySelector('.second-hand');
73-
const minsHand = document.querySelector('.min-hand');
74-
const hourHand = document.querySelector('.hour-hand');
72+
const secondHand = document.querySelector('.second-hand')
73+
const minuteHand = document.querySelector('.min-hand')
74+
const hourHand = document.querySelector('.hour-hand')
7575

76-
function setDate() {
77-
const now = new Date();
76+
minuteHand.style.height = `4px`
77+
secondHand.style.height = `2px`
7878

79-
const seconds = now.getSeconds();
80-
const secondsDegrees = ((seconds / 60) * 360) + 90;
81-
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
82-
83-
const mins = now.getMinutes();
84-
const minsDegrees = ((mins / 60) * 360) + 90;
85-
minsHand.style.transform = `rotate(${minsDegrees}deg)`;
79+
function getDegrees(n) {
80+
return (( n / 60 ) * 360) + 90
81+
}
8682

87-
const hour = now.getMinutes();
88-
const hourDegrees = ((mins / 12) * 360) + 90;
89-
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
83+
function setDate() {
84+
const now = new Date()
85+
const seconds = now.getSeconds()
86+
const minutes = now.getMinutes()
87+
function getHour(){
88+
var rawHour = now.getHours()
89+
if ( rawHour > 12 ) {
90+
return (rawHour - 12) * 5
91+
} else {
92+
return rawHour * 5
93+
}
9094
}
95+
const hours = getHour()
96+
97+
const secondsDegrees = getDegrees(seconds)
98+
const minutesDegrees = getDegrees(minutes)
99+
const hoursDegrees = getDegrees(hours) + ((( minutesDegrees - 90 ) / 360 ) * 30 )
100+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`
101+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`
102+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`
103+
104+
console.log(secondsDegrees + " " + minutesDegrees + " " + hoursDegrees)
105+
console.log(((secondsDegrees - 90) / 360) * 30)
106+
}
91107

92-
setInterval(setDate, 1000);
108+
setInterval(setDate, 1000)
93109

94110
</script>
95111
</body>

0 commit comments

Comments
 (0)