This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
@@ -41,13 +41,30 @@
|
||||
['Dratini', 'Dragonair', 'Dragonite'],
|
||||
];
|
||||
|
||||
const stagesFor = (pokemon) => {};
|
||||
const stagesFor = (pokemon) => {
|
||||
const stages = evolutionStages.find((stages) => stages.includes(pokemon));
|
||||
|
||||
const stagesAfter = (pokemon) => {};
|
||||
if (!stages) {
|
||||
console.warn('stages not found');
|
||||
return [];
|
||||
}
|
||||
|
||||
const stagesBefore = (pokemon) => {};
|
||||
return stages; // wenn unfedined leeres array zurückgeben
|
||||
};
|
||||
|
||||
const stagesAfter = (pokemon) => {
|
||||
const stages = stagesFor(pokemon);
|
||||
|
||||
return stages.slice(stages.indexOf(pokemon) + 1);
|
||||
};
|
||||
|
||||
const stagesBefore = (pokemon) => {
|
||||
const stages = stagesFor(pokemon);
|
||||
return stages.slice(0, stages.indexOf(pokemon));
|
||||
};
|
||||
|
||||
console.log(stagesFor('Vulpix')); // => [ 'Vulpix', 'Ninetales' ]
|
||||
console.log(stagesAfter('Anton')); // =>
|
||||
console.log(stagesAfter('Dratini')); // => [ 'Dragonair', 'Dragonite' ]
|
||||
console.log(stagesBefore('Pidgeot')); // => [ 'Pidgey', 'Pidgeotto' ]
|
||||
console.log(stagesBefore('Dragonair')); // => [ 'Dratini' ]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
@@ -48,7 +48,7 @@
|
||||
];
|
||||
const cocktailRecipes = [honoluluFlip, casualFriday, pinkDolly];
|
||||
|
||||
const ingredientsFromMyBar = [
|
||||
const AVAILABLE_INGREDIENTS = [
|
||||
'Pineapple',
|
||||
'Maracuja Juice',
|
||||
'Cream',
|
||||
@@ -65,19 +65,26 @@
|
||||
];
|
||||
|
||||
const isMixableWithMyIngredients = (cocktailRecipe) => {
|
||||
/* ??? */
|
||||
return isMixableWith(cocktailRecipe, AVAILABLE_INGREDIENTS);
|
||||
};
|
||||
|
||||
const isMixableWith = (cocktailRecipe, availableIngredients) => {
|
||||
return cocktailRecipe.every((ingredientFromRecipe) =>
|
||||
hasIngredient(availableIngredients, ingredientFromRecipe)
|
||||
hasIngredient(availableIngredients, ingredientFromRecipe),
|
||||
);
|
||||
};
|
||||
|
||||
const hasIngredient = (listOfIngredients, searchedIngredient) => listOfIngredients.includes(searchedIngredient);
|
||||
|
||||
// console.log(cocktailRecipes./* ??? */(isMixableWithMyIngredients));
|
||||
const hasIngredient = (listAr, searchStr) => {
|
||||
return listAr.includes(searchStr);
|
||||
};
|
||||
console.log(cocktailRecipes);
|
||||
console.log('isMixable: ', isMixableWith(casualFriday, AVAILABLE_INGREDIENTS));
|
||||
|
||||
console.log(
|
||||
cocktailRecipes.find((recipeAr) => {
|
||||
return isMixableWithMyIngredients(recipeAr);
|
||||
}),
|
||||
);
|
||||
// => [ 'Vodka', 'Lime Juice', 'Apple Juice', 'Cucumber' ]
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
@@ -21,10 +21,48 @@
|
||||
<a href="https://dummyjson.com/users">https://dummyjson.com/users</a> für den Fetch-Aufruf.
|
||||
</p>
|
||||
</div>
|
||||
<div class="output alert alert-secondary my-3"></div>
|
||||
</div>
|
||||
</main>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
const outputEl = document.querySelector('.output');
|
||||
|
||||
const fetchUsers = async () => {
|
||||
try {
|
||||
// Fetch-aufruf an die API
|
||||
const response = await fetch('https://dummyjson.com/users');
|
||||
|
||||
// Prüfen ob die OK ist
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP-Fehler: ${response.status}`);
|
||||
}
|
||||
|
||||
// JSON-Daten parsen
|
||||
const data = await response.json();
|
||||
|
||||
return data;
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
// Funktionsaufruf
|
||||
fetchUsers().then((data) => {
|
||||
console.log(data);
|
||||
console.log(data.users.length);
|
||||
|
||||
outputEl.innerHTML = '';
|
||||
data.users.forEach((user) => {
|
||||
const { firstName, lastName, email } = user;
|
||||
|
||||
console.log(`${firstName} ${lastName} (${email})`);
|
||||
outputEl.innerHTML += `${firstName} ${lastName} (${email})<br />`;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -41,8 +41,12 @@ F. Scott Fitzgerald
|
||||
};
|
||||
|
||||
// JSON String
|
||||
const bookStr = JSON.stringify(book, '', 2);
|
||||
|
||||
console.log(bookStr);
|
||||
|
||||
// JS Object
|
||||
const bookObj = JSON.parse(bookStr);
|
||||
|
||||
console.log(bookObj.title); // => 'The Great Gatsby'
|
||||
console.log(bookObj.author); // => 'F. Scott Fitzgerald'
|
||||
|
||||
Reference in New Issue
Block a user