You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to build a cafe finder with JavaScript
7
7
header: https://i.imgur.com/VKm4oPJ.gif
8
-
bannerImage: https://i.imgur.com/VKm4oPJ.gif
8
+
bannerImage: https://i.imgur.com/lfbCFid.gif
9
9
published: live
10
10
tags:
11
11
- intermediate
12
12
- javascript
13
13
---
14
14
15
15
<BannerImage
16
-
link="https://i.imgur.com/VKm4oPJ.gif"
16
+
link="https://i.imgur.com/lfbCFid.gif"
17
17
description=""
18
18
uid={false}
19
19
cl="for-sidebar"
@@ -29,7 +29,7 @@ tags:
29
29
/>
30
30
31
31
<BannerImage
32
-
link="https://i.imgur.com/VKm4oPJ.gif"
32
+
link="https://i.imgur.com/lfbCFid.gif"
33
33
description=""
34
34
uid="CgUQBagDrWWBRUuoh3mkyi3aedg1"
35
35
/>
@@ -187,8 +187,8 @@ We'll start by creating a container that takes the first saved cafe in our cafe
187
187
188
188
```jsx
189
189
functiondisplayCards(cafes) {
190
-
constcontainer=document.querySelector('.cards');
191
-
container.innerHTML='';
190
+
constcontainer=document.querySelector('.cards');
191
+
container.innerHTML='';
192
192
```
193
193
194
194
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…
198
198
- Adjust the card's **z-index** (display order) so that new cards appear under old ones
199
199
200
200
```jsx
201
-
cafes.forEach((cafe, i) => {
202
-
constwrapper=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
+
constwrapper=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
+
}
210
210
```
211
211
212
212
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
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.
304
304
305
305
```jsx
306
-
else {
306
+
else {
307
307
alert(`${cafe.name} is already saved.`);
308
308
}
309
309
}
@@ -317,8 +317,8 @@ Start by writing a function called `showSaved()`. Similar to the `displayCards()
317
317
318
318
```jsx
319
319
functionshowSaved() {
320
-
constcontainer=document.querySelector('.cards');
321
-
container.innerHTML='';
320
+
constcontainer=document.querySelector('.cards');
321
+
container.innerHTML='';
322
322
```
323
323
324
324
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
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