Skip to content

Commit 0be1038

Browse files
committed
Add function to count and render number of meals
1 parent 2257ac3 commit 0be1038

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
<p>Ready Meals</p>
2222
</div>
2323
<div class="nav-buttons">
24-
<a href="index.html" class="nav-button">Home</a>
24+
<a href="index.html" class="nav-button"
25+
>Meals(<span id="meal-counter"></span>)</a
26+
>
2527
<a href="#Planets" class="nav-button">Planets</a>
2628
<a href="#Races" class="nav-button">Races</a>
2729
</div>

src/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import './style/style.css';
22

33
import API from './modules/data';
4+
import counter from './modules/counter';
45
import render from './modules/render/meals';
56

7+
const mealCounter = document.getElementById('meal-counter');
8+
69
const endpoint = 'https://www.themealdb.com/api/json/v1/1/';
7-
const likesEndpoint = 'https://us-central1-involvement-api.cloudfunctions.net/capstoneApi/apps/lvQFdeSbvijlsDX1Y4VY/likes/';
10+
const likesEndpoint =
11+
'https://us-central1-involvement-api.cloudfunctions.net/capstoneApi/apps/lvQFdeSbvijlsDX1Y4VY/likes/';
812

913
const displayMeals = () => {
1014
Promise.all([
1115
API.getMeals(`${endpoint}search.php?f=b`),
1216
API.getLikes(likesEndpoint),
1317
]).then((data) => {
1418
render(data[0], data[1]);
19+
const length = counter.meals(data[0].meals);
20+
mealCounter.innerText = length;
1521
});
1622
};
1723

18-
window.addEventListener('load', displayMeals);
24+
window.addEventListener('load', displayMeals);

src/modules/counter.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const counter = {
2+
meals: (allMeals) => allMeals.length,
3+
comments: (allComments) => allComments.length,
4+
reservation: (allReservations) => allReservations.length,
5+
};
6+
7+
export default counter;

0 commit comments

Comments
 (0)