close
Skip to content

Commit d8d5714

Browse files
Ánderson Méndez AbelloÁnderson Méndez Abello
authored andcommitted
15 challenges of javascript30
1 parent 61b13da commit d8d5714

19 files changed

Lines changed: 629 additions & 40 deletions

File tree

‎01 - JavaScript Drum Kit/index-START.html‎

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

6060
<script>
6161

62+
function playSound(e){
63+
64+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`)
65+
const key = document.querySelector(`div[data-key="${e.keyCode}"]`)
66+
67+
if(!audio) return; // Escapa todos las teclas que no tengan audio.
68+
69+
audio.currentTime = 0;
70+
audio.play();
71+
key.classList.add('playing');
72+
73+
}
74+
75+
function transitionEnd(e){
76+
77+
if(e.propertyName !== 'transform') return;
78+
79+
console.log(e.propertyName);
80+
console.log(this);
81+
this.classList.remove('playing');
82+
83+
}
84+
85+
const keys = document.querySelectorAll('.key');
86+
keys.forEach(key => key.addEventListener('transitionend', transitionEnd));
87+
window.addEventListener('keydown', playSound)
88+
89+
90+
6291
</script>
6392

6493

‎01 - JavaScript Drum Kit/style.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ body,html {
2323
margin:1rem;
2424
font-size: 1.5rem;
2525
padding:1rem .5rem;
26-
transition:all .07s;
26+
transition:all 1.07s;
2727
width:100px;
2828
text-align: center;
2929
color:white;

‎02 - JS + CSS Clock/index-START.html‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,42 @@
6161
background:black;
6262
position: absolute;
6363
top:50%;
64+
transform-origin: 100%;
65+
transform: rotate(90deg);
66+
transition: all .5s;
67+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
6468
}
6569

6670
</style>
6771

6872
<script>
6973

74+
const secondHand = document.querySelector('.second-hand');
75+
const minHand = document.querySelector('.min-hand');
76+
const hourHand = document.querySelector('.hour-hand');
77+
78+
function setDate(){
79+
const now = new Date();
80+
81+
const seconds = now.getSeconds();
82+
const secondsDegrees = ((seconds/ 60) * 360) + 90;
83+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
84+
console.log('second: ' + seconds);
85+
86+
const mins = now.getMinutes();
87+
const minsDegrees = ((mins/ 60) * 360) + 90;
88+
minHand.style.transform = `rotate(${minsDegrees}deg)`;
89+
console.log('mins: ' + mins);
90+
91+
const hours = now.getHours();
92+
const hoursDegrees = ((hours/ 60) * 360) + 90;
93+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
94+
console.log('hour: ' + hours);
95+
96+
}
97+
98+
setInterval(setDate, 1000)
99+
70100

71101
</script>
72102
</body>

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
99

1010
<div class="controls">
1111
<label for="spacing">Spacing:</label>
12-
<input type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">
12+
<input type="range" name="spacing" min="10" max="200" value="10" data-sizing="px" data-andy="andy">
1313

1414
<label for="blur">Blur:</label>
1515
<input type="range" name="blur" min="0" max="25" value="10" data-sizing="px">
@@ -21,6 +21,22 @@ <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: 0px;
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+
}
39+
2440

2541
/*
2642
misc styles, nothing to do with CSS variables
@@ -53,6 +69,20 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
5369
</style>
5470

5571
<script>
72+
const inputs = document.querySelectorAll('.controls input');
73+
74+
75+
function handleUpdate() {
76+
const suffix = this.dataset.sizing || '';
77+
78+
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
79+
80+
}
81+
82+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
83+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
84+
85+
5686
</script>
5787

5888
</body>

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,100 @@
2828
// Array.prototype.filter()
2929
// 1. Filter the list of inventors for those who were born in the 1500's
3030

31+
console.log('>> 1');
32+
const fifteen = inventors.filter(e => (e.year >= 1499 && e.year <= 1599));
33+
console.table(fifteen);
34+
3135
// Array.prototype.map()
3236
// 2. Give us an array of the inventory first and last names
3337

38+
console.log('>> 2');
39+
const nameFirsts = inventors.map(e => `${e.first} ${e.last}`);
40+
41+
console.log(nameFirsts);
42+
3443
// Array.prototype.sort()
3544
// 3. Sort the inventors by birthdate, oldest to youngest
3645

46+
47+
console.log('>> 3');
48+
const sortBirthdate = inventors.sort((a, b) => a.year - b.year);
49+
50+
console.table(sortBirthdate);
51+
3752
// Array.prototype.reduce()
3853
// 4. How many years did all the inventors live?
3954

55+
console.log('>> 4');
56+
const yearsAllInventors = inventors.reduce(function(a, b){
57+
58+
const Byears = b.passed - b.year;
59+
return a+Byears;
60+
61+
}, 0);
62+
console.log(yearsAllInventors);
63+
4064
// 5. Sort the inventors by years lived
4165

66+
console.log('>> 5');
67+
const oldestToYoungest = inventors.sort(function (a, b){
68+
69+
const Ayears = a.passed - a.year;
70+
const Byears = b.passed - b.year;
71+
72+
return Byears > Ayears ? 1 : -1;
73+
74+
});
75+
76+
console.table(oldestToYoungest);
77+
4278
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4379
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
4480

81+
// const category = document.querySelector('.mw-category');
82+
// const links = Array.from(category.querySelectorAll('a'));
83+
// const de = links
84+
// .map((link) => link.textContent)
85+
// .filter(streetName => streetName.includes('de'));
86+
87+
4588

4689
// 7. sort Exercise
4790
// Sort the people alphabetically by last name
91+
console.log('>> 6');
92+
const alphabeticallySort = people.sort((a, b) => {
93+
const [aLast, aFirst] = a.split(', ');
94+
const [bLast, bFirst] = b.split(', ');
95+
96+
if(bLast < aLast){
97+
return 1;
98+
}
99+
100+
return -1;
101+
});
102+
103+
console.log(alphabeticallySort);
48104

49105
// 8. Reduce Exercise
50106
// Sum up the instances of each of these
107+
108+
console.log('>> 8');
51109
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
52110

111+
const transportation = data.reduce(function(obj, item){
112+
113+
if(!obj[item]){
114+
obj[item] = 0;
115+
}
116+
117+
obj[item]++;
118+
119+
return obj;
120+
121+
}, {})
122+
123+
console.log(transportation)
124+
53125
</script>
54126
</body>
55127
</html>

‎05 - Flex Panel Gallery/index-FINISHED.html‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
background-position:center;
4545
flex: 1;
4646
justify-content: center;
47-
align-items: center;
4847
display: flex;
4948
flex-direction: column;
5049
}

‎05 - Flex Panel Gallery/index-START.html‎

Lines changed: 31 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+
align-items: center;
47+
justify-content: center;
48+
display: flex;
49+
flex-direction: column;
4450
}
4551

4652

@@ -54,8 +60,17 @@
5460
margin:0;
5561
width: 100%;
5662
transition:transform 0.5s;
63+
flex: 1 0 auto;
64+
display: flex;
65+
align-items: center;
66+
justify-content: center;
5767
}
5868

69+
.panel > *:first-child { transform: translateY(-100%); }
70+
.panel.open-active > *:first-child { transform: translateY(0); }
71+
.panel > *:last-child { transform: translateY(100%); }
72+
.panel.open-active > *:last-child { transform: translateY(0); }
73+
5974
.panel p {
6075
text-transform: uppercase;
6176
font-family: 'Amatic SC', cursive;
@@ -67,6 +82,7 @@
6782
}
6883

6984
.panel.open {
85+
flex: 5;
7086
font-size:40px;
7187
}
7288

@@ -108,6 +124,21 @@
108124

109125
<script>
110126

127+
const panels = document.querySelectorAll('.panel');
128+
129+
function toggleOpen(){
130+
this.classList.toggle('open');
131+
}
132+
133+
function toggleActive(e){
134+
if(e.propertyName.includes('flex')){
135+
this.classList.toggle('open-active');
136+
}
137+
}
138+
139+
panels.forEach(panel => panel.addEventListener('click', toggleOpen));
140+
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
141+
111142
</script>
112143

113144

‎06 - Type Ahead/index-START.html‎

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

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

‎06 - Type Ahead/style.css‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
margin: 0;
2323
text-align: center;
2424
outline:0;
25-
border:0;
2625
border: 10px solid #F7F7F7;
2726
width: 120%;
2827
left: -10%;

0 commit comments

Comments
 (0)