Guest User

Untitled

a guest
Nov 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. // manually enumerate ingredients
  2. function renderIngredients(meal) {
  3. let html = '<ul>';
  4. if (meal.strIngredient1 !== '') {
  5. html += `<li>${meal.strMeasure1}: ${meal.strIngredient1}</li>`;
  6. }
  7. if (meal.strIngredient2 !== '') {
  8. html += `<li>${meal.strMeasure2}: ${meal.strIngredient2}</li>`;
  9. }
  10. // write that ^^^ 18 more times...
  11.  
  12.  
  13. html += '</ul>';
  14. return html;
  15. }
  16.  
  17. // fancy way render out ingredients
  18. function renderIngredients(meal) {
  19. // we know there are 20 ingredient fields, so
  20. const list = Array(20).fill().map((_, i) => {
  21. if (meal[`strIngredient${i + 1}`] !== '') {
  22. return `<li>${meal['strMeasure' + (i + 1)]}: ${meal['strIngredient' + (i + 1)]}</li>`;
  23. }
  24. }).filter(x => x !== undefined).join('');
  25. return `<ul>${list}</ul>`;
  26. }
Add Comment
Please, Sign In to add comment