diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index.html similarity index 98% rename from 01 - JavaScript Drum Kit/index-START.html rename to 01 - JavaScript Drum Kit/index.html index 4070d32767..85de0afbfd 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index.html @@ -57,9 +57,7 @@ - +
+ + +diff --git a/01 - JavaScript Drum Kit/index.js b/01 - JavaScript Drum Kit/index.js new file mode 100644 index 0000000000..f52fc4f9fd --- /dev/null +++ b/01 - JavaScript Drum Kit/index.js @@ -0,0 +1,17 @@ +const playSound = e => { + const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`); + const key = document.querySelector(`.key[data-key="${e.keyCode}"]`); + if (!audio) return; + audio.currentTime = 0; + audio.play(); + key.classList.add("playing"); +}; + +const removeTransition = e => { + if (e.propertyName !== "transform") return; + e.target.classList.remove("playing"); +}; + +const keys = document.querySelectorAll(".key"); +keys.forEach(key => key.addEventListener("transitionend", removeTransition)); +window.addEventListener("keydown", playSound); diff --git a/02 - JS and CSS Clock/app.js b/02 - JS and CSS Clock/app.js new file mode 100644 index 0000000000..3be0758d9d --- /dev/null +++ b/02 - JS and CSS Clock/app.js @@ -0,0 +1,21 @@ +const secondHand = document.querySelector('.second-hand'); +const minuteHand = document.querySelector('.min-hand'); +const hourHand = document.querySelector('.hour-hand'); + +function setDate() { + const now = new Date(); + + const seconds = now.getSeconds(); + const secondsDegrees = (seconds / 60) * 360 + 90; + secondHand.style.transform = `rotate(${secondsDegrees}deg)`; + + const minutes = now.getMinutes(); + const minutesDegrees = (minutes / 60) * 360 + 90; + minuteHand.style.transform = `rotate(${minutesDegrees}deg)`; + + const hours = now.getHours(); + const hoursDegrees = (hours / 12) * 360 + 90; + hourHand.style.transform = `rotate(${hoursDegrees}deg)`; +} + +setInterval(setDate, 1000); diff --git a/02 - JS and CSS Clock/clock.html b/02 - JS and CSS Clock/clock.html new file mode 100644 index 0000000000..c4445b7626 --- /dev/null +++ b/02 - JS and CSS Clock/clock.html @@ -0,0 +1,76 @@ + + + +
+ +
+ + +
+ +