Skip to content

Commit 6739b49

Browse files
committed
wesbos#6 completed!
1 parent d98f172 commit 6739b49

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

05 - Flex Panel Gallery/index-START.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
}
3030

3131
.panel {
32+
direction: flex;
33+
flex-direction: column;
3234
background: #6B0F9C;
3335
box-shadow: inset 0 0 0 5px rgba(255,255,255,0.1);
3436
color: white;

06 - Type Ahead/index-START.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,38 @@
1616
</form>
1717
<script>
1818
const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json';
19+
let search = document.querySelector('.search').addEventListener('input', (e) => {
20+
// console.log(e.target.value);
21+
fetch(endpoint)
22+
.then(r => r.json())
23+
.then(r => r.filter(cityObj => cityObj.city.toLowerCase().includes(e.target.value.toLowerCase())))
24+
.then(r => {
25+
let suggestionsSection = document.querySelector('.suggestions');
26+
while (suggestionsSection.firstChild) {
27+
suggestionsSection.removeChild(suggestionsSection.firstChild);
28+
}
29+
r.forEach(cityObj => {
30+
let { city, state, population } = cityObj;
31+
let cityLI = document.createElement('li');
32+
let cityText = document.createTextNode(`${city}, ${state}`);
1933

34+
let populationSpan = document.createElement('span')
35+
populationSpan.classList.add('population');
36+
let populationWithCommas = population.split('');
37+
let counter = 0;
38+
for (let i = populationWithCommas.length; i > 0; i -= 1) {
39+
if (counter % 3 === 0 && counter !== 0) {
40+
populationWithCommas.splice(i, 0, ',')
41+
}
42+
counter += 1;
43+
}
44+
populationSpan.append(populationWithCommas.join(''));
45+
46+
cityLI.append(cityText, populationSpan);
47+
suggestionsSection.appendChild(cityLI)
48+
});
49+
});
50+
});
2051
</script>
2152
</body>
2253
</html>

0 commit comments

Comments
 (0)