Skip to content

Commit 67bfd70

Browse files
committed
challenge 1-11
1 parent 5c4b856 commit 67bfd70

File tree

12 files changed

+452
-13
lines changed

12 files changed

+452
-13
lines changed

01 - JavaScript Drum Kit/index-START.html

+43
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,49 @@
5858
<audio data-key="76" src="sounds/tink.wav"></audio>
5959

6060
<script>
61+
const keys = document.querySelectorAll('.key'),
62+
audio = document.querySelectorAll('audio'),
63+
soundsMap = ( () => {
64+
const map = new Map();
65+
66+
audio.forEach( sound => map.set( sound.dataset.key, sound ) );
67+
68+
return map;
69+
70+
})(),
71+
click = function (e) {
72+
play( soundsMap.get(this.dataset.key), this );
73+
},
74+
transition = function (e) {
75+
if( e.propertyName === 'transform' ) {
76+
this.classList.remove('playing')
77+
}
78+
},
79+
play = (sound, el) => {
80+
81+
if( ! sound ) {
82+
return;
83+
}
84+
85+
el.classList.add('playing');
86+
sound.currentTime = 0;
87+
sound.play();
88+
89+
};
90+
91+
92+
keys.forEach( function(key) {
93+
key.addEventListener( 'click', click )
94+
key.addEventListener( 'transitionend', transition )
95+
});
96+
97+
window.addEventListener('keyup', function(event) {
98+
const keyCode = event.keyCode.toString(),
99+
el = document.querySelector(`.key[data-key="${keyCode}"]`)
100+
play( soundsMap.get( keyCode ), el );
101+
});
102+
103+
61104

62105
</script>
63106

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

+43-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
<div class="clock">
1111
<div class="clock-face">
12-
<div class="hand hour-hand"></div>
13-
<div class="hand min-hand"></div>
14-
<div class="hand second-hand"></div>
12+
<div class="hand hour-hand transition"></div>
13+
<div class="hand min-hand transition"></div>
14+
<div class="hand second-hand transition"></div>
1515
</div>
1616
</div>
1717

@@ -62,11 +62,51 @@
6262
background: black;
6363
position: absolute;
6464
top: 50%;
65+
transform: rotate(90deg);
66+
transform-origin: 100%;
67+
}
68+
.hour-hand {
69+
left: 25%;
70+
height: 10px;
71+
width: 25%
72+
}
73+
.transition {
74+
transition: all 0.5s;
75+
transition-timing-function: cubic-bezier(0.15, 3.53, 0.58, 1);
6576
}
6677

78+
6779
</style>
6880

6981
<script>
82+
const setTime = (e) => {
83+
const date = new Date,
84+
secondsDegrees = ( ( date.getSeconds() / 60 ) * 360 ) + 90,
85+
minuteDegree = ( ( date.getMinutes() / 60 ) * 360 ) + 90,
86+
hourDegree = ( ( date.getHours() / 12 ) * 360 ) + 90,
87+
handSec = document.querySelector('.second-hand'),
88+
handMin = document.querySelector('.min-hand'),
89+
handHour = document.querySelector('.hour-hand');
90+
if ( secondsDegrees === 90 ) {
91+
handSec.classList.remove('transition');
92+
} else if ( secondsDegrees === 96 ) {
93+
handSec.classList.add('transition');
94+
}
95+
96+
if ( secondsDegrees >= 444 ) {
97+
98+
} else if ( secondsDegrees <= 96 ) {
99+
console.log( ': ', secondsDegrees );
100+
}
101+
handSec.style.transform = `rotate(${secondsDegrees}deg)`;
102+
handMin.style.transform = `rotate(${minuteDegree}deg)`;
103+
handHour.style.transform = `rotate(${hourDegree}deg)`;
104+
},
105+
setHour = () => {
106+
107+
},
108+
intSec = setInterval(setTime, 1000);
109+
70110

71111

72112
</script>

03 - CSS Variables/index-START.html

+21
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2626
misc styles, nothing to do with CSS variables
2727
*/
2828

29+
:root {
30+
--base: #888888;
31+
--spacing: 10px;
32+
--blur: 10px;
33+
}
34+
35+
img {
36+
padding: var(--spacing);
37+
background: var(--base);
38+
filter: blur(var(--blur));
39+
}
40+
2941
body {
3042
text-align: center;
3143
background: #193549;
@@ -45,6 +57,15 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4557
</style>
4658

4759
<script>
60+
const inputs = document.querySelectorAll('.controls input'),
61+
update = function(){
62+
const docEl = document.documentElement.style,
63+
sizing = this.dataset.sizing || '' ;
64+
docEl.setProperty(`--${this.id}`, `${this.value}${sizing}`);
65+
console.log(this.value)
66+
};
67+
inputs.forEach( input => input.addEventListener('change', update));
68+
inputs.forEach( input => input.addEventListener('mousemove', update));
4869
</script>
4970

5071
</body>

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

+22-3
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,48 @@
3131

3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
34-
34+
const bornIn1500 = inventors.filter( i => i.year >= 1500 && i.year < 1600 )
35+
console.log( 'bornIn1500: ', bornIn1500 );
3536
// Array.prototype.map()
3637
// 2. Give us an array of the inventors' first and last names
38+
const firstLastName = inventors.map( i => ( `${i.first} ${i.last}` ) );
39+
console.log( 'firstLastName: ', firstLastName );
3740

3841
// Array.prototype.sort()
3942
// 3. Sort the inventors by birthdate, oldest to youngest
40-
43+
const sort = inventors.sort( (a,b)=> a.year - b.year )
44+
console.log( 'sort: ', sort );
4145
// Array.prototype.reduce()
4246
// 4. How many years did all the inventors live?
47+
const reduce = inventors.reduce( (lived, i) => (i.passed - i.year) + lived, 0)
48+
console.log( 'reduce: ', reduce );
4349

4450
// 5. Sort the inventors by years lived
51+
const sortLived = inventors.sort( (a,b) => (a.passed - a.year) - (b.passed - b.year))
52+
console.log( 'sortLived: ', sortLived );
4553

4654
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4755
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
56+
// const links = document.querySelectorAll('.mw-category a'),
57+
// de = Array.prototype.map.call(links, a => a.innerText)
58+
// .filter(a => a.indexOf('de') !== -1 )
4859

4960

5061
// 7. sort Exercise
5162
// Sort the people alphabetically by last name
52-
63+
const peopleSort = people.sort((a,b) => a.split(',')[1] < b.split(',')[1] ? -1 : 1 )
64+
console.log( 'peopleSort: ', peopleSort );
5365
// 8. Reduce Exercise
5466
// Sum up the instances of each of these
5567
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
5668

69+
const dataReduce = data.reduce((obj, a) => {
70+
obj[a] = ! obj[a] ? 1 : obj[a] += 1;
71+
return obj;
72+
} , {} )
73+
74+
console.dir(dataReduce)
75+
5776
</script>
5877
</body>
5978
</html>

05 - Flex Panel Gallery/index-START.html

+39-4
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,9 @@
4344
font-size: 20px;
4445
background-size: cover;
4546
background-position: center;
47+
display: flex;
48+
flex-direction: column;
49+
flex: 1;
4650
}
4751

4852
.panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
@@ -56,20 +60,33 @@
5660
margin: 0;
5761
width: 100%;
5862
transition: transform 0.5s;
63+
display: flex;
64+
flex: 1 0 auto;
65+
justify-content: center;
66+
align-items: center;
67+
}
68+
.panel p:first-child {
69+
transform: translateY(-100%);
70+
}
71+
.panel p:last-child {
72+
transform: translateY(100%);
73+
}
74+
.panel.open-active p:first-child, .panel.open-active p:last-child {
75+
transform: translateY(0);
5976
}
60-
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,7 +122,25 @@
105122
</div>
106123

107124
<script>
125+
const panels = document.querySelectorAll('.panel'),
126+
togglePanels = function(){
127+
panels.forEach( el => {
128+
if( this !== el ) {
129+
el.classList.remove('open');
130+
}
131+
});
132+
this.classList.toggle('open');
133+
},
134+
transition = function (e) {
135+
if( e.propertyName.includes('flex') ) {
136+
this.classList.toggle('open-active');
137+
}
138+
};
108139

140+
panels.forEach(function(el) {
141+
el.addEventListener('click', togglePanels )
142+
el.addEventListener( 'transitionend', transition )
143+
})
109144
</script>
110145

111146

06 - Type Ahead/index-START.html

+31-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,37 @@
1515
</ul>
1616
</form>
1717
<script>
18-
const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json';
18+
const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json',
19+
cities = [],
20+
search = document.querySelector('.search'),
21+
suggestions = document.querySelector('.suggestions'),
22+
numberWithCommas = function (x) {
23+
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
24+
},
25+
filter = function() {
26+
const str = this.value.toLowerCase(),
27+
filtered = cities.filter( loc=> loc.city.toLowerCase().indexOf(str) !== -1 || loc.state.toLowerCase().indexOf(str) !== -1 )
28+
.map( a => {
29+
const reg = new RegExp( str, 'gi' ),
30+
city = a.city.replace(reg, `<span class="hl">${this.value}</span>`),
31+
state = a.state.replace(reg,`<span class="hl">${this.value}</span>`);
32+
33+
return `<li>
34+
<span class="name">${city}, ${state}</span>
35+
<span class="population"> ${numberWithCommas(a.population)}</span>
36+
</li>`;
37+
})
38+
.join('');
39+
40+
suggestions.innerHTML = filtered;
41+
42+
};
43+
44+
search.addEventListener('keyup', filter )
45+
46+
fetch(endpoint)
47+
.then(a => a.json() )
48+
.then(a => cities.push(...a))
1949

2050
</script>
2151
</body>

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

+25
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,40 @@
2626

2727
// Some and Every Checks
2828
// Array.prototype.some() // is at least one person 19 or older?
29+
const some19 = people.some( p => ( (new Date).getFullYear() ) - p.year >= 19 )
30+
console.log( 'some19: ', some19 );
2931
// Array.prototype.every() // is everyone 19 or older?
32+
const every19 = people.every( p => ( (new Date).getFullYear() ) - p.year >= 19 )
33+
console.log( 'every19: ', every19 );
34+
3035

3136
// Array.prototype.find()
3237
// Find is like filter, but instead returns just the one you are looking for
3338
// find the comment with the ID of 823423
39+
const find = comments.find(c => c.id === 823423 )
40+
console.log( 'find: ', find );
3441

3542
// Array.prototype.findIndex()
3643
// Find the comment with this ID
3744
// delete the comment with the ID of 823423
45+
const index = comments.findIndex( c => c.id === 823423 ),
46+
47+
newComments = [
48+
49+
...comments.slice(0,index),
50+
...comments.slice(index +1)
51+
52+
53+
];
54+
55+
console.log( 'newComments: ', newComments );
56+
57+
58+
//comments.splice( index, 1 );
59+
60+
console.log( 'comments: ', comments );
61+
62+
3863

3964
</script>
4065
</body>

0 commit comments

Comments
 (0)