Skip to content

Commit 3e7e822

Browse files
committed
Solutions to exercises 1, 2 and beginning of 4
1 parent d6e74c1 commit 3e7e822

4 files changed

Lines changed: 59 additions & 2 deletions

File tree

01 - JavaScript Drum Kit/index-START.html

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99

1010

1111
<div class="keys">
12+
<p>
13+
<div data-key="54" class="key">
14+
<kbd>6</kbd>
15+
<span class="sound">tink</span>
16+
</div></br></br>
17+
</p>
18+
<p>
1219
<div data-key="65" class="key">
1320
<kbd>A</kbd>
1421
<span class="sound">clap</span>
@@ -45,6 +52,7 @@
4552
<kbd>L</kbd>
4653
<span class="sound">tink</span>
4754
</div>
55+
</p>
4856
</div>
4957

5058
<audio data-key="65" src="sounds/clap.wav"></audio>
@@ -56,11 +64,32 @@
5664
<audio data-key="74" src="sounds/snare.wav"></audio>
5765
<audio data-key="75" src="sounds/tom.wav"></audio>
5866
<audio data-key="76" src="sounds/tink.wav"></audio>
67+
<audio data-key="54" src="sounds/tink.wav"></audio>
5968

6069
<script>
61-
70+
71+
function playSound(e) {
72+
console.log(e.keyCode);
73+
74+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
75+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
76+
if (!audio) return; // stop the function from running altogether
77+
audio.currentTime = 0; // rewind to the start
78+
audio.play();
79+
key.classList.add('playing');
80+
}
81+
82+
function removeTransition(e) {
83+
if (e.propertyName !== 'transform') return; //skip it if it's not a transform
84+
this.classList.remove('playing');
85+
}
86+
87+
const keys = document.querySelectorAll('.key');
88+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
89+
window.addEventListener('keydown', playSound);
6290
</script>
6391

6492

6593
</body>
6694
</html>
95+

01 - JavaScript Drum Kit/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ body,html {
3434

3535
.playing {
3636
transform: scale(1.1);
37-
border-color: #ffc600;
37+
border-color: #0004ff;
3838
box-shadow: 0 0 1rem #ffc600;
3939
}
4040

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,38 @@
6262
background: black;
6363
position: absolute;
6464
top: 50%;
65+
transform-origin: 100%;
66+
transform: rotate(90deg);
67+
transition: all 0.05s;
68+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
6569
}
6670

6771
</style>
6872

6973
<script>
74+
const secondHand = document.querySelector('.second-hand');
75+
const minuteHand = document.querySelector('.min-hand');
76+
const hourHand = document.querySelector('.hour-hand');
77+
78+
function setDate() {
79+
const now = new Date();
80+
81+
const seconds = now.getSeconds();
82+
const secondsDegrees = ((seconds / 60) * 360) + 90;
83+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
7084

85+
const minutes = now.getMinutes();
86+
const minutesDegrees = ((minutes / 60) * 360) + 90;
87+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
88+
89+
const hours = now.getHours();
90+
const hoursDegrees = ((hours / 12) * 360) + 90;
91+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
92+
93+
console.log(seconds);
94+
}
7195

96+
setInterval(setDate, 1000);
7297
</script>
7398
</body>
7499
</html>

04 - Array Cardio Day 1/index-START.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
// Array.prototype.filter()
3939
// 1. Filter the list of inventors for those who were born in the 1500's
40+
const inventorsBornIn1500s = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600);
41+
42+
console.table(inventorsBornIn1500s);
4043

4144
// Array.prototype.map()
4245
// 2. Give us an array of the inventors first and last names

0 commit comments

Comments
 (0)