Advertisement
Guest User

Untitled

a guest
Jan 4th, 2022
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let queries = []
  2.  
  3. async function fetchCategories() {
  4.  
  5.   const response = await fetch('https://www.themealdb.com/api/json/v1/1/categories.php')
  6.   const data = await response.json()
  7.  
  8.   categories = data.categories.map(category => (
  9.     queries.push(category.strCategory)
  10.   ))
  11.  
  12.   return queries
  13. }
  14.  
  15. async function fetchFood(query) {
  16.   const response = await fetch(`https://www.themealdb.com/api/json/v1/1/filter.php?c=${query}`)
  17.   const data = await response.json()
  18.  
  19.   document.getElementById('root').innerHTML += `<h1>${query}</h1>`
  20.   data.meals.map(meal => (
  21.     document.getElementById("root").innerHTML += `${meal.strMeal}</br>`
  22.   ))
  23. }
  24.  
  25. fetchCategories()
  26.   .then(result => {
  27.     for (query of result) {
  28.       fetchFood(query)
  29.     }
  30.   }
  31. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement