Visitar URL original
Day 2 · wesbos/JavaScript30@6069e93 · GitHub
Skip to content

Commit 6069e93

Browse files
author
Ryan
committed
Day 2
1 parent afa58ed commit 6069e93

2 files changed

Lines changed: 57 additions & 5 deletions

File tree

‎03 - CSS Variables/index-START.html‎

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

2323
<style>
24-
24+
:root {
25+
--base: #ffc600;
26+
--spacing: 20px;
27+
--blur: 10px;
28+
}
29+
img {
30+
padding: var(--spacing);
31+
background: var(--base);
32+
filter:blur(var(--blur));
33+
}
34+
.hl {
35+
color: var(--base);
36+
}
2537
/*
2638
misc styles, nothing to do with CSS variables
2739
*/
@@ -48,6 +60,14 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4860
</style>
4961

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

5373
</body>

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

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<title>Array Cardio 💪</title>
66
</head>
77
<body>
8-
<p><em>Psst: have a look at the JavaScript Console</em> 💁</p>
98
<script>
109
// Get your shorts on - this is an array workout!
1110
// ## Array Cardio Day 1
@@ -33,29 +32,62 @@
3332

3433
// Array.prototype.filter()
3534
// 1. Filter the list of inventors for those who were born in the 1500's
35+
const born1500 = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year < 1600));
36+
console.log(born1500);
3637

3738
// Array.prototype.map()
3839
// 2. Give us an array of the inventors' first and last names
40+
const firstLast = inventors.map(inventor => (`${inventor.first} ${inventor.last}`);
41+
console.log(firstLast);
3942

4043
// Array.prototype.sort()
4144
// 3. Sort the inventors by birthdate, oldest to youngest
45+
const sorted = inventors.sort((a, b) => (a.year > b.year ? 1 : -1);
46+
console.log(sorted);
4247

4348
// Array.prototype.reduce()
4449
// 4. How many years did all the inventors live?
50+
const totalYear = inventors.reduce((prev, next)=> {
51+
return prev + (next.passed - next.year)
52+
},0);
53+
console.log(totalYear);
4554

4655
// 5. Sort the inventors by years lived
56+
const yearLived = inventors.sort((a, b) => {
57+
const aLived = a.passed - a.year;
58+
const bLived = b.passed - b.year;
59+
return aLived > bLived ? -1 : 1;
60+
});
4761

62+
console.log(yearLived);
4863
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4964
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
50-
51-
65+
// const category = document.querySelector('.mw-category');
66+
// const link = Array.from(category.querySelectorAll('a'));
67+
// const de = link
68+
// .map(data => (data.textContent))
69+
// .filter(name => name.includes('de'))
70+
// console.log(de);
5271
// 7. sort Exercise
5372
// Sort the people alphabetically by last name
73+
const sortLastName = people.sort((a, b) => {
74+
const [aFirst, aLast] = a.split(', ');
75+
const [bFirst, bLast] = b.split(', ');
76+
return aLast.localeCompare(bLasts);
77+
})
5478

79+
console.log(sortLastName);
5580
// 8. Reduce Exercise
5681
// Sum up the instances of each of these
5782
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
58-
83+
const sumInstance = data.reduce((prev, next)=> {
84+
if (!prev[next]) {
85+
prev[next] = 0;
86+
}
87+
prev[next]++;
88+
return prev;
89+
},{})
90+
console.log(sumInstance);
5991
</script>
6092
</body>
6193
</html>

0 commit comments

Comments
 (0)