You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

script.js 686B

12345678910111213141516171819202122
  1. let btnRandomRecipe = document.getElementById("random-recipe");
  2. let elRecipes = document.getElementById("recipes");
  3. btnRandomRecipe.addEventListener("click", async () => {
  4. let recipe = await fetch("/api/random-recipe.php", { method: "POST" })
  5. .then(res => res.json());
  6. let el = document.createElement("div");
  7. el.className = "recipe"
  8. let elName = document.createElement("div");
  9. elName.className = "recipe-name"
  10. elName.innerText = recipe.name;
  11. el.appendChild(elName);
  12. let elDifficulty = document.createElement("div");
  13. elDifficulty.className = "recipe-difficulty";
  14. elDifficulty.innerText = recipe.difficulty;
  15. el.appendChild(elDifficulty);
  16. elRecipes.appendChild(el);
  17. });