Skip to content

Commit 2d58b25

Browse files
committed
Challenge wesbos#2
1 parent 8966f8d commit 2d58b25

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

01 - JavaScript Drum Kit/index-START.html

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

6060
<script>
61+
window.addEventListener('keydown',function(e){
62+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`)
63+
if (!audio) return
64+
audio.currentTime = 0;
65+
audio.play();
6166

67+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`)
68+
key.classList.add("playing")
69+
70+
function removeTransition (e){
71+
key.classList.remove("playing")
72+
}
73+
74+
const keys = document.querySelectorAll(".key");
75+
keys.forEach(key => key.addEventListener('transitionend' , removeTransition));
76+
77+
// console.log(audio);
78+
// console.log(key);
79+
});
6280
</script>
6381

6482

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,36 @@
6262
background: black;
6363
position: absolute;
6464
top: 50%;
65+
transform-origin: 100% 50%;
66+
transform: rotate(90deg);
67+
transition: all 1s;
68+
transition-timing-function: cubic-bezier(0.075, 0.82, 0.165, 1)
6569
}
6670

6771
</style>
6872

6973
<script>
7074

75+
const secondHand = document.querySelector(".second-hand")
76+
// secondHand refers to the "seconds" hand
77+
78+
function setDate(){
79+
const now = new Date();
80+
const seconds = now.getSeconds();
81+
const secondDegrees = ((seconds / 60) * 360) + 90;
82+
83+
secondHand.style.transform = `rotate(${secondDegrees}deg)`
84+
85+
const mins = now.getMinutes();
86+
const minsDegrees = ((mins / 60) * 360) + ((seconds/60)*6) + 90;
87+
minsHand.style.transform = `rotate(${minsDegrees}deg)`;
88+
89+
const hour = now.getHours();
90+
const hourDegrees = ((hour / 12) * 360) + ((mins/60)*30) + 90;
91+
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
92+
}
93+
94+
setInterval(setDate, 1000)
7195

7296
</script>
7397
</body>

0 commit comments

Comments
 (0)