Skip to content

Commit 3498ce1

Browse files
committed
Completed 1-5 & 7
1 parent 650e837 commit 3498ce1

File tree

6 files changed

+184
-0
lines changed

6 files changed

+184
-0
lines changed

01 - JavaScript Drum Kit/index-START.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@
5959

6060
<script>
6161

62+
function playSound(e){
63+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
64+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
65+
if (!audio) return; // stop the function from running all together
66+
audio.currentTime = 0; // rewind to start
67+
audio.play();
68+
key.classList.add('playing');
69+
}
70+
71+
function removeTransition(e) {
72+
if (e.propertyName !== 'transform') return; // skip it if not a transform
73+
this.classList.remove('playing');
74+
}
75+
76+
const keys = document.querySelectorAll('.key');
77+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
78+
window.addEventListener('keydown', playSound);
79+
6280
</script>
6381

6482

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,46 @@
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);
69+
}
70+
71+
.second-hand {
72+
height: 4px;
73+
background-color: rgba(255,0,0,.25);
74+
}
75+
76+
.min-hand {
77+
background-color: rgba(255,255,0,.25);
78+
}
79+
80+
.hour-hand {
81+
height: 10px;
82+
background-color: rgba(255,0,255,.25);
6583
}
6684

6785
</style>
6886

6987
<script>
88+
const hourHand = document.querySelector('.hour-hand');
89+
const minHand = document.querySelector('.min-hand');
90+
const secondHand = document.querySelector('.second-hand');
7091

92+
function setDate() {
93+
const now = new Date();
94+
const hours = now.getHours();
95+
const mins = now.getMinutes();
96+
const seconds = now.getSeconds();
97+
const hoursDegrees = ((hours / 12) * 360) + 90;
98+
const minsDegrees = ((mins / 60) * 360) + 90;
99+
const secondsDegrees = ((seconds / 60) * 360) + 90;
100+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
101+
minHand.style.transform = `rotate(${minsDegrees}deg)`;
102+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
103+
}
104+
setInterval(setDate, 1000);
71105

72106
</script>
73107
</body>

03 - CSS Variables/index-START.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2222

2323
<style>
2424

25+
:root {
26+
--base: #ffc600;
27+
--spacing: 10px;
28+
--blur: 10px;
29+
}
30+
31+
img {
32+
padding: var(--spacing);
33+
background: var(--base);
34+
filter: blur(var(--blur));
35+
}
36+
37+
.hl {
38+
color: var(--base);
39+
}
40+
2541
/*
2642
misc styles, nothing to do with CSS variables
2743
*/
@@ -45,6 +61,16 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4561
</style>
4662

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

5076
</body>

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,71 @@
3131

3232
// Array.prototype.filter()
3333
// 1. Filter the list of inventors for those who were born in the 1500's
34+
const fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year < 1600));
35+
36+
console.table(fifteen);
3437

3538
// Array.prototype.map()
3639
// 2. Give us an array of the inventors' first and last names
3740

41+
const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`);
42+
43+
console.log(fullNames);
44+
45+
3846
// Array.prototype.sort()
3947
// 3. Sort the inventors by birthdate, oldest to youngest
4048

49+
const ordered = inventors.sort((a,b) => a.year > b.year ? 1 : -1);
50+
console.table(ordered);
51+
4152
// Array.prototype.reduce()
4253
// 4. How many years did all the inventors live?
4354

55+
const totalYears = inventors.reduce((total,inventor) => {
56+
return total + (inventor.passed - inventor.year);
57+
}, 0);
58+
59+
console.log(totalYears);
60+
4461
// 5. Sort the inventors by years lived
62+
const oldest = inventors.sort((a,b) => a.passed - a.year <= b.passed - b.year ? 1 : -1);
63+
console.table(oldest);
64+
4565

4666
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4767
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
4868

69+
// const category = document.querySelector('.mw-category');
70+
// const links = Array.from(category.querySelectorAll('a'));
71+
//
72+
// const de = links
73+
// .map(link => link.textContent)
74+
// .filter(streetName => streetName.includes('de '));
4975

5076
// 7. sort Exercise
5177
// Sort the people alphabetically by last name
5278

79+
const alpha = people.sort((lastOne,nextOne) => {
80+
const [alast, afirst] = lastOne.split(", ");
81+
const [blast, bfirst] = nextOne.split(", ");
82+
return alast > blast ? 1 : -1;
83+
});
84+
85+
console.log(alpha);
86+
5387
// 8. Reduce Exercise
5488
// Sum up the instances of each of these
5589
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
5690

91+
const transportation = data.reduce(function(obj,item) {
92+
if(!obj[item]) {
93+
obj[item] = 0;
94+
}
95+
obj[item]++;
96+
return obj;
97+
}, {});
98+
5799
</script>
58100
</body>
59101
</html>

05 - Flex Panel Gallery/index-START.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
.panels {
2525
min-height:100vh;
2626
overflow: hidden;
27+
display: flex;
2728
}
2829

2930
.panel {
@@ -41,6 +42,11 @@
4142
font-size: 20px;
4243
background-size:cover;
4344
background-position:center;
45+
flex: 1;
46+
justify-content: center;
47+
align-items: center;
48+
display: flex;
49+
flex-direction: column;
4450
}
4551

4652

@@ -50,12 +56,35 @@
5056
.panel4 { background-image:url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); }
5157
.panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); }
5258

59+
/* flex items */
5360
.panel > * {
5461
margin:0;
5562
width: 100%;
5663
transition:transform 0.5s;
64+
/* border: 1px solid red; */
65+
flex: 1 0 auto;
66+
display: flex;
67+
justify-content: center;
68+
align-items: center;
5769
}
5870

71+
.panel > *:first-child {
72+
transform: translateY(-100%);
73+
}
74+
75+
.panel.open-active > *:first-child {
76+
transform: translateY(0);
77+
}
78+
79+
.panel > *:last-child {
80+
transform: translateY(100%);
81+
}
82+
83+
.panel.open-active > *:last-child {
84+
transform: translateY(0);
85+
}
86+
87+
5988
.panel p {
6089
text-transform: uppercase;
6190
font-family: 'Amatic SC', cursive;
@@ -67,6 +96,7 @@
6796
}
6897

6998
.panel.open {
99+
flex: 5;
70100
font-size:40px;
71101
}
72102

@@ -102,6 +132,20 @@
102132
</div>
103133

104134
<script>
135+
const panels = document.querySelectorAll('.panel');
136+
137+
function toggleOpen() {
138+
this.classList.toggle('open');
139+
}
140+
141+
function toggleActive(e) {
142+
if(e.propertyName.includes('flex')) {
143+
this.classList.toggle('open-active');
144+
}
145+
}
146+
147+
panels.forEach(panel => panel.addEventListener('click', toggleOpen ));
148+
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive ));
105149

106150
</script>
107151

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,36 @@
2626

2727
// Some and Every Checks
2828
// Array.prototype.some() // is at least one person 19 or older?
29+
const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19 );
30+
31+
console.log({isAdult});
2932
// Array.prototype.every() // is everyone 19 or older?
33+
const allAdult = people.every(person => ((new Date()).getFullYear()) - person.year >= 19 );
3034

35+
console.log({allAdult});
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
3439

40+
const comment = comments.find(comment => (comment.id === 823423));
41+
42+
console.log({comment});
43+
3544
// Array.prototype.findIndex()
3645
// Find the comment with this ID
3746
// delete the comment with the ID of 823423
3847

48+
const index = comments.findIndex(comment => (comment.id === 542328))
49+
50+
console.log(index);
51+
52+
// comments.splice(index, 1);
53+
54+
const newComments = [
55+
...comments.slice(0, index),
56+
...comments.slice(index + 1)
57+
];
58+
3959
</script>
4060
</body>
4161
</html>

0 commit comments

Comments
 (0)