Skip to content

Commit 7b9b7f4

Browse files
author
nrvarun
committed
Day 1 and Day 2 completed
1 parent 5029405 commit 7b9b7f4

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

01 - JavaScript Drum Kit/index-START.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,21 @@
5858
<audio data-key="76" src="sounds/tink.wav"></audio>
5959

6060
<script>
61+
const keys = document.querySelectorAll('.key');
62+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
63+
function removeTransition(e) {
64+
this.classList.remove('playing');
65+
}
6166

67+
function playSound(e) {
68+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
69+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
70+
key.classList.add('playing');
71+
console.log()
72+
audio.currentTime = 0;
73+
audio.play();
74+
}
75+
window.addEventListener('keydown', playSound);
6276
</script>
6377

6478

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,44 @@
6262
position: absolute;
6363
top:50%;
6464
}
65+
.second-hand {
66+
height: 3px;
67+
background-color: #fefefe;
68+
box-shadow: 1px 1px 2px grey;
69+
transform: rotate(90deg);
70+
transform-origin: right;
71+
}
72+
.min-hand,
73+
.hour-hand {
74+
transform: rotate(90deg);
75+
transform-origin: right;
76+
transition: all 0.05s cubic-bezier(0, 2.87, 1, 1.41);
77+
}
6578

6679
</style>
6780

6881
<script>
82+
function setTime() {
83+
84+
const now = new Date();
85+
const mins = now.getMinutes();
86+
const hrs = now.getHours();
87+
const secs = now.getSeconds();
88+
89+
const hrsDeg = ((hrs/12)*360) + 90;
90+
const secsDeg = ((secs / 60) * 360) + 90;
91+
const minsDeg = ((mins / 60) * 360) + 90;
92+
93+
const secHand = document.querySelector('.hand.second-hand');
94+
const minHand = document.querySelector('.hand.min-hand');
95+
const hourHand = document.querySelector('.hand.hour-hand');
96+
97+
secHand.style.transform = `rotate(${secsDeg}deg)`;
98+
minHand.style.transform = `rotate(${minsDeg}deg)`;
99+
hourHand.style.transform = `rotate(${hrsDeg}deg)`;
100+
}
69101

102+
setInterval(setTime, 100);
70103

71104
</script>
72105
</body>

0 commit comments

Comments
 (0)