Skip to content

Commit bda9ade

Browse files
committed
1-7 Completed
1 parent d6e74c1 commit bda9ade

File tree

7 files changed

+143
-7
lines changed

7 files changed

+143
-7
lines changed

01 - JavaScript Drum Kit/index-START.html

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

6060
<script>
61+
function removeTransition(e) {
62+
if (e.propertyName !== 'transform') return;
63+
this.classList.remove('playing');
64+
};
65+
66+
function playSound(e) {
67+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
68+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
69+
if (!audio) return;
70+
audio.currentTime = 0;
71+
audio.play();
72+
key.classList.add('playing');
73+
}
74+
75+
window.addEventListener('keydown', playSound);
76+
const keys = document.querySelectorAll('.key');
77+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
6178

6279
</script>
6380

03 - CSS Variables/index-START.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2121
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
2222

2323
<style>
24+
:root {
25+
--base: #ffc600;
26+
--spacing: 10px;
27+
--blur: 10px;
28+
}
29+
30+
img {
31+
padding: var(--spacing);
32+
background: var(--base);
33+
filter: blur(var(--blur));
34+
}
35+
36+
.hl {
37+
color: var(--base);
38+
}
2439

2540
/*
2641
misc styles, nothing to do with CSS variables
@@ -45,6 +60,15 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4560
</style>
4661

4762
<script>
63+
const inputs = document.querySelectorAll('.controls input');
64+
65+
function handleUpdate() {
66+
const suffix = this.dataset.sizing || '';
67+
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
68+
}
69+
70+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
71+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
4872
</script>
4973

5074
</body>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'Berne, Eric', 'Berra, Yogi', 'Berry, Wendell', 'Bevan, Aneurin', 'Ben-Gurion, David', 'Bevel, Ken', 'Biden, Joseph', 'Bennington, Chester', 'Bierce, Ambrose',
3535
'Billings, Josh', 'Birrell, Augustine', 'Blair, Tony', 'Beecher, Henry', 'Biondo, Frank'
3636
];
37-
37+
3838
// Array.prototype.filter()
3939
// 1. Filter the list of inventors for those who were born in the 1500's
4040
const fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year < 1600));

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,57 @@
3434
'Berne, Eric', 'Berra, Yogi', 'Berry, Wendell', 'Bevan, Aneurin', 'Ben-Gurion, David', 'Bevel, Ken', 'Biden, Joseph', 'Bennington, Chester', 'Bierce, Ambrose',
3535
'Billings, Josh', 'Birrell, Augustine', 'Blair, Tony', 'Beecher, Henry', 'Biondo, Frank'
3636
];
37-
37+
3838
// Array.prototype.filter()
3939
// 1. Filter the list of inventors for those who were born in the 1500's
40+
var filtered = inventors.filter(inventor => inventor.year > 1499 && inventor.year < 1600);
4041

4142
// Array.prototype.map()
4243
// 2. Give us an array of the inventors first and last names
44+
var names = inventors.map(inventor => inventor.first + ' ' + inventor.last);
4345

4446
// Array.prototype.sort()
4547
// 3. Sort the inventors by birthdate, oldest to youngest
48+
var sorted = inventors.sort((inventor, next) => inventor.year > next.year ? 1 : -1);
4649

4750
// Array.prototype.reduce()
4851
// 4. How many years did all the inventors live all together?
52+
var yearsLived = inventors.reduce(function(yrs, inventor) {
53+
return yrs += inventor.passed - inventor.year;
54+
}, 0);
4955

5056
// 5. Sort the inventors by years lived
57+
var oldest = inventors.sort((inventor, next) => inventor.passed - inventor.year < next.passed - next.year ? 1 : -1);
5158

5259
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
5360
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
54-
61+
// const category = document.querySelector('.mw-category');
62+
// const links = Array.from(category.querySelectorAll('a'));
63+
// const de = links
64+
// .map(link => link.textContent)
65+
// .filter(streetName => streetName.includes('de'));
5566

5667
// 7. sort Exercise
5768
// Sort the people alphabetically by last name
5869

70+
// My Solution
71+
var sortedLastNames = people.sort((person, nextPerson) => person.split(', ')[0] > nextPerson.split(', ')[0] ? 1 : -1);
72+
73+
// Wes Solution
74+
var alpha = people.sort((lastOne, nextOne) => {
75+
var [aLast, aFirst] = lastOne.split(', ')[0];
76+
var [bLast, bFirst] = nextOne.split(', ')[0];
77+
aLast > bLast ? 1 : -1;
78+
});
79+
5980
// 8. Reduce Exercise
6081
// Sum up the instances of each of these
6182
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
6283

84+
var transportation = data.reduce(function(acc, item) {
85+
acc[item] = acc[item] + 1 || 1;
86+
return acc;
87+
}, {});
6388
</script>
6489
</body>
6590
</html>

05 - Flex Panel Gallery/index-START.html

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
font-size: 20px;
1515
font-weight: 200;
1616
}
17-
17+
1818
body {
1919
margin: 0;
2020
}
21-
21+
2222
*, *:before, *:after {
2323
box-sizing: inherit;
2424
}
2525

2626
.panels {
2727
min-height: 100vh;
2828
overflow: hidden;
29+
display: flex;
2930
}
3031

3132
.panel {
@@ -43,6 +44,11 @@
4344
font-size: 20px;
4445
background-size: cover;
4546
background-position: center;
47+
flex: 1;
48+
justify-content: center;
49+
align-items: center;
50+
display: flex;
51+
flex-direction: column;
4652
}
4753

4854
.panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
@@ -56,20 +62,31 @@
5662
margin: 0;
5763
width: 100%;
5864
transition: transform 0.5s;
65+
flex: 1 0 auto;
66+
display: flex;
67+
justify-content: center;
68+
align-items: center;
5969
}
6070

71+
.panel > *:first-child { transform: translateY(-100%); }
72+
.panel.open-active > *:first-child { transform: translateY(0); }
73+
74+
.panel > *:last-child { transform: translateY(100%); }
75+
.panel.open-active > *:last-child { transform: translateY(0); }
76+
6177
.panel p {
6278
text-transform: uppercase;
6379
font-family: 'Amatic SC', cursive;
6480
text-shadow: 0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45);
6581
font-size: 2em;
6682
}
67-
83+
6884
.panel p:nth-child(2) {
6985
font-size: 4em;
7086
}
7187

7288
.panel.open {
89+
flex: 5;
7390
font-size: 40px;
7491
}
7592

@@ -105,10 +122,21 @@
105122
</div>
106123

107124
<script>
125+
const panels = document.querySelectorAll('.panel');
108126

109-
</script>
127+
function toggleOpen() {
128+
this.classList.toggle('open');
129+
}
110130

131+
function toggleActive(e) {
132+
if (e.propertyName.includes('flex')) {
133+
this.classList.toggle('open-active');
134+
}
135+
}
111136

137+
panels.forEach(panel => panel.addEventListener('click', toggleOpen));
138+
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
139+
</script>
112140

113141
</body>
114142
</html>

06 - Type Ahead/index-START.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,42 @@
1717
<script>
1818
const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json';
1919

20+
const cities = [];
21+
22+
fetch(endpoint)
23+
.then(blob => blob.json())
24+
.then(data => cities.push(...data));
25+
26+
function findMatches(wordToMatch, cities) {
27+
return cities.filter(place => {
28+
const regex = new RegExp(wordToMatch, 'gi');
29+
return place.city.match(regex) || place.state.match(regex);
30+
})
31+
}
32+
33+
function displayMatches() {
34+
const matchArray = findMatches(this.value, cities);
35+
36+
const html = matchArray.map(place => {
37+
const regex = new RegExp(this.value, 'gi');
38+
const cityName = place.city.replace(regex, `<span class="hl">${this.value}</span>`);
39+
const stateName = place.state.replace(regex, `<span class="hl">${this.value}</span>`)
40+
41+
return `
42+
<li>
43+
<span class="name">${cityName}, ${stateName}</span>
44+
<span class="population">${parseInt(place.population).toLocaleString()}</span>
45+
</li>
46+
`;
47+
}).join('');
48+
suggestions.innerHTML = html;
49+
}
50+
51+
const searchInput = document.querySelector('.search');
52+
const suggestions = document.querySelector('.suggestions');
53+
54+
searchInput.addEventListener('change', displayMatches);
55+
searchInput.addEventListener('keyup', displayMatches);
2056
</script>
2157
</body>
2258
</html>

07 - Array Cardio Day 2/index-START.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@
2727
// Some and Every Checks
2828
// Array.prototype.some() // is at least one person 19 or older?
2929
// Array.prototype.every() // is everyone 19 or older?
30+
var someAre = people.some(person => new Date().getFullYear() - person.year > 18);
31+
var allAre = people.every(person => new Date().getFullYear() - person.year > 18);
3032

3133
// Array.prototype.find()
3234
// Find is like filter, but instead returns just the one you are looking for
3335
// find the comment with the ID of 823423
36+
var cmt823423 = comments.find(comment => comment.id === 823423);
3437

3538
// Array.prototype.findIndex()
3639
// Find the comment with this ID
3740
// delete the comment with the ID of 823423
41+
var index = comments.findIndex(comment => comment.id === 823423);
42+
var newComments = comments.slice(0);
43+
newComments.splice(index, 1);
3844

3945
</script>
4046
</body>

0 commit comments

Comments
 (0)