Skip to content

Commit 22552bc

Browse files
committed
Fixing this whole thing
Seriously. I'm gonna fix it all today.
1 parent f43588b commit 22552bc

File tree

4 files changed

+91
-76
lines changed

4 files changed

+91
-76
lines changed

exercises/01 - JavaScript Drum Kit/index.html

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,41 @@
6565
* the keypress, add a class to the specific element that matches with the keypress,
6666
* and then remove that class in order to reset the element to it's original state.
6767
*/
68-
function playSound(e) {
69-
const soundclip = document.querySelector(`audio[data-key="${e.keyCode}"]`);
70-
const keyelement = document.querySelector(`.key[data-key="${e.keyCode}"]`);
7168

72-
if (!soundclip) return; // Stop function from running if key pressed doesn't match up with our elements
69+
(function () {
70+
const playSound = (e) => {
71+
const soundclip = document.querySelector(`audio[data-key="${e.keyCode}"]`);
72+
const keyelement = document.querySelector(`.key[data-key="${e.keyCode}"]`);
7373

74-
keyelement.classList.add('playing');
74+
if (!soundclip) return undefined; // Stop function from running if key pressed doesn't match up with our elements
7575

76-
soundclip.currentTime = 0; // Play sound clip from start every time a corresponding key is pressed
77-
soundclip.play();
78-
}
76+
keyelement.classList.add('playing');
7977

80-
function removeTransition(e) {
81-
if (e.propertyName !== 'transform') return; // skip if it's not a transform event
82-
this.classList.remove('playing');
83-
}
78+
soundclip.currentTime = 0; // Play sou
8479

85-
const keys = document.querySelectorAll('.key'); // Find all elements in the document with a class 'key'
86-
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
80+
soundclip.play();
81+
}
8782

88-
window.addEventListener('keydown', playSound);
83+
const removeTransition = (e) => {
84+
// skip if it's not a transform event
85+
if (e.propertyName !== 'transform') return undefined;
86+
e.target.classList.remove('playing');
87+
}
88+
89+
// Find all elements in the document with a class 'key'
90+
const keys = document.querySelectorAll('.key');
91+
92+
window.addEventListener('keydown', playSound);
93+
94+
keys.forEach(key =>
95+
key.addEventListener(
96+
'transitionend',
97+
(e) => removeTransition.call(key, e)
98+
)
99+
);
100+
})();
89101
</script>
90102

91103
</body>
92104

93-
</html>
105+
</html>

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

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,46 @@
1919

2020
<style>
2121
html {
22-
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
23-
background-size:cover;
24-
font-family:'helvetica neue';
22+
background: #018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
23+
background-size: cover;
24+
font-family: 'helvetica neue';
2525
text-align: center;
2626
font-size: 10px;
2727
}
28-
28+
2929
body {
3030
font-size: 2rem;
31-
display:flex;
32-
flex:1;
31+
display: flex;
32+
flex: 1;
3333
min-height: 100vh;
3434
align-items: center;
3535
}
36-
36+
3737
.clock {
3838
width: 30rem;
3939
height: 30rem;
40-
border:20px solid white;
41-
border-radius:50%;
42-
margin:50px auto;
40+
border: 20px solid white;
41+
border-radius: 50%;
42+
margin: 50px auto;
4343
position: relative;
44-
padding:2rem;
45-
box-shadow:
46-
0 0 0px 4px rgba(0,0,0,0.1),
47-
inset 0 0 0 3px #EFEFEF,
48-
inset 0 0 10px black,
49-
0 0 10px rgba(0,0,0,0.2);
44+
padding: 2rem;
45+
box-shadow: 0 0 0px 4px rgba(0, 0, 0, 0.1), inset 0 0 0 3px #EFEFEF, inset 0 0 10px black, 0 0 10px rgba(0, 0, 0, 0.2);
5046
}
51-
47+
5248
.clock-face {
5349
position: relative;
5450
width: 100%;
5551
height: 100%;
56-
transform: translateY(-3px); /* account for the height of the clock hands */
52+
transform: translateY(-3px);
53+
/* account for the height of the clock hands */
5754
}
58-
55+
5956
.hand {
60-
width:50%;
61-
height:6px;
62-
background:black;
57+
width: 50%;
58+
height: 6px;
59+
background: black;
6360
position: absolute;
64-
top:50%;
61+
top: 50%;
6562
transform-origin: 100%;
6663
transform: rotate(90deg);
6764
transition: all 0.05s;
@@ -70,39 +67,38 @@
7067

7168
</style>
7269

73-
<script>
74-
/* GOAL: Write the JavaScript code necessary to transform the HTML elements
70+
<script>
71+
/* GOAL: Write the JavaScript code necessary to transform the HTML elements
7572
* on the page into a functioning clock.
7673
*/
7774

78-
// Create references to the HTML elements that we want to transform
79-
const secondHand = document.querySelector('.second-hand');
80-
const minuteHand = document.querySelector('.min-hand');
81-
const hourHand = document.querySelector('.hour-hand')
75+
// Create references to the HTML elements that we want to transform
76+
const
77+
secondHand = document.querySelector('.second-hand'),
78+
minuteHand = document.querySelector('.min-hand'),
79+
hourHand = document.querySelector('.hour-hand')
80+
const calcDegrees = (int, div) => ((int / div) * 360) + 90;
81+
// Call function once every second
82+
setInterval(() => {
8283

83-
function setDate() {
84-
const now = new Date(); // Create new Date object
84+
// Create new Date object
85+
const now = new Date();
8586

86-
// Get current seconds, calculate the degree shift, and apply the styling
87-
const seconds = now.getSeconds();
88-
const secondHandDegrees = ((seconds / 60) * 360) + 90;
89-
secondHand.style.transform = `rotate(${secondHandDegrees}deg)`;
87+
// Get current seconds, minutes, & hours and calculate the degree shift
88+
const
89+
secondHandDegrees = calcDegrees(now.getSeconds(), 60),
90+
minuteHandDegrees = calcDegrees(now.getMinutes(), 60),
91+
hourHandDegrees = calcDegrees(now.getHours(), 12);
9092

91-
// Get current minutes, calculate the degree shift, and apply the styling
92-
const minutes = now.getMinutes();
93-
const minuteHandDegrees = ((minutes / 60) * 360) + 90;
94-
minuteHand.style.transform = `rotate(${minuteHandDegrees}deg)`;
9593

96-
// Hour hand transformation can utilize the data gathered for the minute
97-
// hand, with a minor alteration in how the degree shift is calculated.
98-
const hourHandDegrees = ((minutes / 12) * 360) + 90;
99-
hourHand.style.transform = `rotate(${hourHandDegrees}deg)`;
100-
}
94+
// Apply rotation to the clock hands corresponding with current time value
95+
secondHand.style.transform = `rotate(${secondHandDegrees}deg)`;
96+
minuteHand.style.transform = `rotate(${minuteHandDegrees}deg)`;
97+
hourHand.style.transform = `rotate(${hourHandDegrees}deg)`;
10198

102-
// Call function once every second
103-
setInterval(setDate, 1000);
10499

105-
</script>
100+
}, 1000);
101+
</script>
106102
</body>
107103

108-
</html>
104+
</html>

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525

2626
const flavours = ['Chocolate Chip', 'Kulfi', 'Caramel Praline', 'Chocolate', 'Burnt Caramel', 'Pistachio', 'Rose', 'Sweet Coconut', 'Lemon Cookie', 'Toffeeness', 'Toasted Almond', 'Black Raspberry Crunch', 'Chocolate Brownies', 'Pistachio Almond', 'Strawberry', 'Lavender Honey', 'Lychee', 'Peach', 'Black Walnut', 'Birthday Cake', 'Mexican Chocolate', 'Mocha Almond Fudge', 'Raspberry'];
2727

28-
const people = ['Beck, Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Berger, Ric', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton', 'Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black Elk', 'Blair, Robert', 'Blair, Tony', 'Blake, William'];
28+
const people = ['Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black Elk', 'Blair, Robert', 'Blair, Tony', 'Blake, William', 'Beck, Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Berger, Ric', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton',];
2929

3030
// Array.prototype.filter()
3131
// 1. Filter the list of inventors for those who were born in the 1500's
32-
const inventors_from_1500s = inventors.filter((inventor) => inventor.year >= 1500 && inventor.year < 1600)
32+
const inventors_from_1500s = inventors.filter(
33+
(inventor) => inventor.year >= 1500 && inventor.year < 1600
34+
)
35+
3336
console.table(inventors_from_1500s)
3437

3538
// Array.prototype.map()
@@ -44,10 +47,15 @@
4447

4548
// Array.prototype.reduce()
4649
// 4. How many years did all the inventors live?
47-
const total_years_lived = inventors.reduce((currValue, inventor) => currValue += (inventor.passed - inventor.year), 0)
50+
const total_years_lived = inventors.reduce(
51+
(currValue, inventor) => currValue += (inventor.passed - inventor.year), 0
52+
)
4853
console.log(total_years_lived);
54+
4955
// 5. Sort the inventors by years lived
50-
const inventors_by_lifespan = inventors.sort((a, b) => (a.passed - a.year) - (b.passed - b.year));
56+
const inventors_by_lifespan = inventors.sort(
57+
(a, b) => (a.passed - a.year) - (b.passed - b.year)
58+
);
5159
console.table(inventors_by_lifespan);
5260

5361
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
@@ -63,10 +71,10 @@
6371

6472
// 7. sort Exercise
6573
// Sort the people alphabetically by last name
66-
const people_by_last_name = people.sort(
67-
(a, b) => a.split(', ')[0] > b.split(', ')[0] ? -1 : 1);
6874

69-
console.table(people_by_last_name);
75+
const people_by_last_name = people.sort((a, b) => a.split(', ')[0] < b.split(', ')[0] ? -1 : 1);
76+
77+
console.log(people_by_last_name);
7078
// 8. Reduce Exercise
7179
// Sum up the instances of each of these
7280
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck'];
@@ -79,9 +87,8 @@
7987
return tallyObject;
8088
}, {});
8189

82-
console.table(data_instance_count);
83-
90+
console.log(data_instance_count);
8491
</script>
8592
</body>
8693

87-
</html>
94+
</html>

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ This repository contains my written guides for the JavaScript30 course by
1414
refer back to. Orrr you're in a library and don't have headphones. Who knows! If
1515
you want some documentation to go along with those sweet Wes Bos vids, here you go.
1616

17-
**DISCLAIMER:** My approach to some of the challenges vary from the provided answers (found in
17+
**DISCLAIMER:** My approach to some of the challenges will vary from the provided answers (found in
1818
the files that end with `-FINISHED` on the main repo). Some of the tweaks are just to
1919
include various 'best practices' and some have huge chunks of differences. I try to provide
20-
thorough explanations when I do sway from the path and explain why I chose to do so, but
20+
thorough explanations when I do stray from the path and explain why I chose to do so, but
2121
I want to make it clear that some of these guides don't go hand-in-hand with the videos.
2222

2323
## About

0 commit comments

Comments
 (0)