Skip to content

Commit c284d9f

Browse files
author
Gilbert Bagaoisan
committed
day 2
1 parent fe83039 commit c284d9f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

01 - JavaScript Drum Kit/index-START.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@
5959

6060
<script>
6161

62+
function playSound(e) {
63+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
64+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
65+
66+
if (!audio) return;
67+
68+
// rewind to the start
69+
audio.currentTime = 0;
70+
audio.play();
71+
key.classList.add('playing');
72+
}
73+
74+
// transition end event
75+
function removeTransition(e) {
76+
if (e.propertyName !== 'transform') return;
77+
this.classList.remove('playing')
78+
}
79+
80+
const keys = document.querySelectorAll('.key');
81+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
82+
83+
window.addEventListener('keydown', playSound);
6284
</script>
6385

6486

02 - JS + CSS Clock/index-START.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,36 @@
6161
background:black;
6262
position: absolute;
6363
top:50%;
64+
transform-origin: 100%;
65+
transform: rotate(90deg);
66+
transition: all 0.05s;
67+
transition-timing-function: cubic-bezier(0, 2.63, 0.58, 1);
6468
}
6569

6670
</style>
6771

6872
<script>
6973

74+
const secondHand = document.querySelector('.second-hand');
75+
const minHand = document.querySelector('.min-hand');
76+
const hourHand = document.querySelector('.hour-hand');
77+
78+
function setDate() {
79+
const now = new Date();
80+
const seconds = now.getSeconds();
81+
const secondsDegrees = ((seconds / 60) * 360) + 90;
82+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
83+
84+
const mins = now.getMinutes();
85+
const minsDegrees = ((mins / 60) * 360) + 90;
86+
minHand.style.transform = `rotate(${minsDegrees}deg)`;
87+
88+
const hour = now.getHours();
89+
const hourDegrees = ((mins / 12) * 360) + 90;
90+
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
91+
}
92+
93+
setInterval(setDate, 1000);
7094

7195
</script>
7296
</body>

0 commit comments

Comments
 (0)