Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: fixed the issue that was occuring while clicking the view recipe…#48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
umeshves wants to merge1 commit intosahandghavidel:main
base:main
Choose a base branch
Loading
fromumeshves:fix-issue
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 3 additions & 37 deletionsprojects/recipe-book-app/index.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<title>Recipe Book App</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
Expand All@@ -14,44 +14,10 @@ <h1>Recipe Book App</h1>

<div class="container">
<ul id="recipe-list" class="recipe-list">
<!-- <li class="recipe-item">
<img
src="https://spoonacular.com/recipeImages/12345-312x231.jpg"
alt="Recipe 1"
/>
<h2>Recipe 1</h2>
<p>
<strong>Ingredients:</strong> Ingredient 1, Ingredient 2, Ingredient
3
</p>
<a href="#">View Recipe</a>
</li>
<li class="recipe-item">
<img
src="https://spoonacular.com/recipeImages/12545-312x231.jpg"
alt="Recipe 2"
/>
<h2>Recipe 2</h2>
<p>
<strong>Ingredients:</strong> Ingredient 1, Ingredient 2, Ingredient
3
</p>
<a href="#">View Recipe</a>
</li>
<li class="recipe-item">
<img
src="https://spoonacular.com/recipeImages/12445-312x231.jpg"
alt="Recipe 3"
/>
<h2>Recipe 3</h2>
<p>
<strong>Ingredients:</strong> Ingredient 1, Ingredient 2, Ingredient
3
</p>
<a href="#">View Recipe</a>
</li> -->
<li>Loading recipes...</li>
</ul>
</div>

<script src="index.js"></script>
</body>
</html>
41 changes: 26 additions & 15 deletionsprojects/recipe-book-app/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
const API_KEY = "275d58779ccf4e22af03e792e8819fff";
const API_KEY = "cf4b2745d2b64605bd47a2d231b6dcf7"; // Replace with your valid API key
const recipeListEl = document.getElementById("recipe-list");

function displayRecipes(recipes) {
recipeListEl.innerHTML = "";
recipeListEl.innerHTML = ""; // Clear any existing content, including "Loading recipes..."
recipes.forEach((recipe) => {
const recipeItemEl = document.createElement("li");
recipeItemEl.classList.add("recipe-item");
recipeImageEl = document.createElement("img");

const recipeImageEl = document.createElement("img");
recipeImageEl.src = recipe.image;
recipeImageEl.alt ="recipe image";
recipeImageEl.alt =`${recipe.title} image`;

recipeTitleEl = document.createElement("h2");
constrecipeTitleEl = document.createElement("h2");
recipeTitleEl.innerText = recipe.title;

recipeIngredientsEl = document.createElement("p");
constrecipeIngredientsEl = document.createElement("p");
recipeIngredientsEl.innerHTML = `
<strong>Ingredients:</strong> ${recipe.extendedIngredients
.map((ingredient) => ingredient.original)
.join(", ")}
`;

recipeLinkEl = document.createElement("a");
constrecipeLinkEl = document.createElement("a");
recipeLinkEl.href = recipe.sourceUrl;
recipeLinkEl.innerText = "View Recipe";

Expand All@@ -33,18 +34,28 @@ function displayRecipes(recipes) {
}

async function getRecipes() {
const response = await fetch(
`https://api.spoonacular.com/recipes/random?number=10&apiKey=${API_KEY}`
);

const data = await response.json();

return data.recipes;
try {
const response = await fetch(
`https://api.spoonacular.com/recipes/random?number=10&apiKey=${API_KEY}`
);

if (!response.ok) {
throw new Error("Failed to fetch recipes");
}

const data = await response.json();
return data.recipes;
} catch (error) {
console.error(error);
recipeListEl.innerHTML = `<li>Error fetching recipes. Please try again later.</li>`;
}
}

async function init() {
const recipes = await getRecipes();
displayRecipes(recipes);
if (recipes) {
displayRecipes(recipes);
}
}

init();

[8]ページ先頭

©2009-2025 Movatter.jp