Skip to content

Commit 57ceff1

Browse files
authored
Merge pull request #210 from gbanaag/main
updated the banner image and code indentation
2 parents 29a75c6 + 1292846 commit 57ceff1

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

projects/build-a-cafe-finder-with-javascript/build-a-cafe-finder-with-javascript.mdx

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ uid: CgUQBagDrWWBRUuoh3mkyi3aedg1
55
datePublished: 2025-08-06
66
description: Learn how to build a cafe finder with JavaScript
77
header: https://i.imgur.com/VKm4oPJ.gif
8-
bannerImage: https://i.imgur.com/VKm4oPJ.gif
8+
bannerImage: https://i.imgur.com/lfbCFid.gif
99
published: live
1010
tags:
1111
- intermediate
1212
- javascript
1313
---
1414

1515
<BannerImage
16-
link="https://i.imgur.com/VKm4oPJ.gif"
16+
link="https://i.imgur.com/lfbCFid.gif"
1717
description=""
1818
uid={false}
1919
cl="for-sidebar"
@@ -29,7 +29,7 @@ tags:
2929
/>
3030

3131
<BannerImage
32-
link="https://i.imgur.com/VKm4oPJ.gif"
32+
link="https://i.imgur.com/lfbCFid.gif"
3333
description=""
3434
uid="CgUQBagDrWWBRUuoh3mkyi3aedg1"
3535
/>
@@ -187,8 +187,8 @@ We'll start by creating a container that takes the first saved cafe in our cafe
187187
188188
```jsx
189189
function displayCards(cafes) {
190-
const container = document.querySelector('.cards');
191-
container.innerHTML = '';
190+
const container = document.querySelector('.cards');
191+
container.innerHTML = '';
192192
```
193193
194194
We'll then make a for loop that iterates through the cafe list to…
@@ -198,15 +198,15 @@ We'll then make a for loop that iterates through the cafe list to…
198198
- Adjust the card's **z-index** (display order) so that new cards appear under old ones
199199
200200
```jsx
201-
cafes.forEach((cafe, i) => {
202-
const wrapper = document.createElement('div');
203-
wrapper.className = 'swipe-wrapper';
204-
wrapper.style.zIndex = 200 - i;
205-
206-
var newCards = document.querySelectorAll('.location-card:not(.removed)');
207-
var allCards = document.querySelectorAll('.location-card');
208-
});
209-
}
201+
cafes.forEach((cafe, i) => {
202+
const wrapper = document.createElement('div');
203+
wrapper.className = 'swipe-wrapper';
204+
wrapper.style.zIndex = 200 - i;
205+
206+
var newCards = document.querySelectorAll('.location-card:not(.removed)');
207+
var allCards = document.querySelectorAll('.location-card');
208+
});
209+
}
210210
```
211211
212212
We'll add more inside the function that inserts location information into each card by calling the Places API. Add a line that creates a card div and another line that assigns the card's class name to be ``location-card``.
@@ -263,17 +263,17 @@ We're going to add a function that detects left and right swipes and makes each
263263
264264
```jsx
265265
const hammertime = new Hammer(wrapper);
266-
hammertime.on('swipeleft', () => {
267-
wrapper.style.transform = 'translateX(-150%) rotate(-15deg)';
268-
wrapper.style.opacity = 0;
269-
setTimeout(() => wrapper.remove(), 100);
270-
});
271-
hammertime.on('swiperight', () => {
272-
saveCafe(JSON.stringify(cafeData));
273-
wrapper.style.transform = 'translateX(150%) rotate(15deg)';
274-
wrapper.style.opacity = 0;
275-
setTimeout(() => wrapper.remove(), 100);
276-
});
266+
hammertime.on('swipeleft', () => {
267+
wrapper.style.transform = 'translateX(-150%) rotate(-15deg)';
268+
wrapper.style.opacity = 0;
269+
setTimeout(() => wrapper.remove(), 100);
270+
});
271+
hammertime.on('swiperight', () => {
272+
saveCafe(JSON.stringify(cafeData));
273+
wrapper.style.transform = 'translateX(150%) rotate(15deg)';
274+
wrapper.style.opacity = 0;
275+
setTimeout(() => wrapper.remove(), 100);
276+
});
277277
```
278278
279279
### Saving Cafes
@@ -303,7 +303,7 @@ if (!saved.find(c => c.place_id === cafe.place_id)) {
303303
We'll need a fallback in case the cafe is already saved. Write an `else` statement that alerts the user if a cafe has already been saved, so it doesn't get duplicated into the saved list of cafes.
304304
305305
```jsx
306-
else {
306+
else {
307307
alert(`${cafe.name} is already saved.`);
308308
}
309309
}
@@ -317,8 +317,8 @@ Start by writing a function called `showSaved()`. Similar to the `displayCards()
317317
318318
```jsx
319319
function showSaved() {
320-
const container = document.querySelector('.cards');
321-
container.innerHTML = '';
320+
const container = document.querySelector('.cards');
321+
container.innerHTML = '';
322322
```
323323
324324
Then, add this line to parse through the list of saved cafes and save the information in a variable.
@@ -331,9 +331,9 @@ If the saved array is empty, it'll update the page by adding a ``<p>`` tag to sa
331331
332332
```jsx
333333
if (saved.length === 0) {
334-
container.innerHTML = '<p>No saved cafes yet 😢</p>';
335-
return;
336-
}
334+
container.innerHTML = '<p>No saved cafes yet 😢</p>';
335+
return;
336+
}
337337
```
338338
339339
For each cafe in the saved array, we'll make a card div, add the `location-card` class name, and update the card's content with `innerHTML` to include the current cafe's information.

0 commit comments

Comments
 (0)