This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
@@ -35,7 +35,29 @@
|
|||||||
['Russia', 'Moscow'],
|
['Russia', 'Moscow'],
|
||||||
];
|
];
|
||||||
|
|
||||||
const getCountryForCapital = () => {};
|
const getCountryForCapital = (capital) => {
|
||||||
|
for (const [country, countryCapital] of countriesWithCapital) {
|
||||||
|
if (countryCapital === capital) {
|
||||||
|
return country;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCountryForCapital2 = (capital) => {
|
||||||
|
const foundCountryAr = countriesWithCapital.find(
|
||||||
|
(arr) => arr[1].trim().toLowerCase() === capital.trim().toLowerCase(),
|
||||||
|
);
|
||||||
|
|
||||||
|
return foundCountryAr ? foundCountryAr[0] : undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('London:', getCountryForCapital2('London')); // => London: UK
|
||||||
|
console.log('London:', getCountryForCapital2('london')); // => London: UK
|
||||||
|
console.log('London:', getCountryForCapital2('')); // => London: undefined
|
||||||
|
console.log('Paris:', getCountryForCapital2('Paris')); // => Paris: France
|
||||||
|
console.log('Vienna:', getCountryForCapital2('Vienna')); // => Vienna: Austria
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
@@ -41,16 +41,41 @@
|
|||||||
['Dratini', 'Dragonair', 'Dragonite'],
|
['Dratini', 'Dragonair', 'Dragonite'],
|
||||||
];
|
];
|
||||||
|
|
||||||
const stagesFor = (pokemon) => {};
|
const stagesFor = (pokemon) => {
|
||||||
|
const stages = evolutionStages.find((stages) => stages.includes(pokemon));
|
||||||
|
return stages ? stages : [];
|
||||||
|
};
|
||||||
|
|
||||||
const stagesAfter = (pokemon) => {};
|
const stagesAfter = (pokemon) => {
|
||||||
|
const stages = stagesFor(pokemon);
|
||||||
|
const index = stages.indexOf(pokemon);
|
||||||
|
|
||||||
const stagesBefore = (pokemon) => {};
|
// wenn nicht gefunden
|
||||||
|
if (index === -1) return [];
|
||||||
|
|
||||||
|
return stages.slice(index + 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
const stagesBefore = (pokemon) => {
|
||||||
|
const stages = stagesFor(pokemon);
|
||||||
|
const index = stages.indexOf(pokemon);
|
||||||
|
|
||||||
|
// wenn nicht gefunden
|
||||||
|
if (index === -1) return [];
|
||||||
|
|
||||||
|
return stages.slice(0, index);
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(stagesFor('Bulbasaur')); // => undefined
|
||||||
console.log(stagesFor('Vulpix')); // => [ 'Vulpix', 'Ninetales' ]
|
console.log(stagesFor('Vulpix')); // => [ 'Vulpix', 'Ninetales' ]
|
||||||
|
|
||||||
console.log(stagesAfter('Dratini')); // => [ 'Dragonair', 'Dragonite' ]
|
console.log(stagesAfter('Dratini')); // => [ 'Dragonair', 'Dragonite' ]
|
||||||
|
console.log(stagesAfter('Bulbasaur')); // => undefined
|
||||||
|
console.log(stagesAfter('Dragonite')); // => []
|
||||||
|
|
||||||
console.log(stagesBefore('Pidgeot')); // => [ 'Pidgey', 'Pidgeotto' ]
|
console.log(stagesBefore('Pidgeot')); // => [ 'Pidgey', 'Pidgeotto' ]
|
||||||
console.log(stagesBefore('Dragonair')); // => [ 'Dratini' ]
|
console.log(stagesBefore('Dragonair')); // => [ 'Dratini' ]
|
||||||
|
|
||||||
console.log(stagesBefore('Pidgey')); // => []
|
console.log(stagesBefore('Pidgey')); // => []
|
||||||
console.log(stagesBefore('Pidgeot')); // => ['Pidgey', 'Pidgeotto']
|
console.log(stagesBefore('Pidgeot')); // => ['Pidgey', 'Pidgeotto']
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
@@ -64,19 +64,19 @@
|
|||||||
'Cucumber',
|
'Cucumber',
|
||||||
];
|
];
|
||||||
|
|
||||||
const isMixableWithMyIngredients = (cocktailRecipe) => {
|
const isMixableWithMyIngredients = (cocktailRecipe, allIngredients = ingredientsFromMyBar) => {
|
||||||
/* ??? */
|
return isMixableWith(cocktailRecipe, allIngredients);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isMixableWith = (cocktailRecipe, availableIngredients) => {
|
const isMixableWith = (cocktailRecipe, availableIngredients) => {
|
||||||
return cocktailRecipe.every((ingredientFromRecipe) =>
|
return cocktailRecipe.every((ingredientFromRecipe) =>
|
||||||
hasIngredient(availableIngredients, ingredientFromRecipe)
|
hasIngredient(availableIngredients, ingredientFromRecipe),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasIngredient = (listOfIngredients, searchedIngredient) => listOfIngredients.includes(searchedIngredient);
|
const hasIngredient = (listOfIngredients, searchedIngredient) => listOfIngredients.includes(searchedIngredient);
|
||||||
|
|
||||||
// console.log(cocktailRecipes./* ??? */(isMixableWithMyIngredients));
|
console.log(cocktailRecipes.find((cocktailRecipe) => isMixableWithMyIngredients(cocktailRecipe)));
|
||||||
|
|
||||||
// => [ 'Vodka', 'Lime Juice', 'Apple Juice', 'Cucumber' ]
|
// => [ 'Vodka', 'Lime Juice', 'Apple Juice', 'Cucumber' ]
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
@@ -25,6 +25,30 @@
|
|||||||
</main>
|
</main>
|
||||||
<script>
|
<script>
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// async function fetchUsers() {
|
||||||
|
const fetchUsers = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('https://dummyjson.com/users');
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP-Fehler: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json(); // HTTP-Response Body
|
||||||
|
// console.log(data.users);
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Benutzer konnten nicht geladen werden:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchUsers().then((data) => {
|
||||||
|
data.users.forEach((user) => {
|
||||||
|
const { firstName = '', lastName = '', age } = user;
|
||||||
|
console.log(`name: ${firstName}, lastname: ${lastName}, age: ${age}\n`);
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -41,9 +41,11 @@ F. Scott Fitzgerald
|
|||||||
};
|
};
|
||||||
|
|
||||||
// JSON String
|
// JSON String
|
||||||
|
const jsonString = JSON.stringify(book, null, 2);
|
||||||
|
console.log(jsonString);
|
||||||
|
|
||||||
// JS Object
|
// JS Object
|
||||||
|
const bookObj = JSON.parse(jsonString);
|
||||||
console.log(bookObj.title); // => 'The Great Gatsby'
|
console.log(bookObj.title); // => 'The Great Gatsby'
|
||||||
console.log(bookObj.author); // => 'F. Scott Fitzgerald'
|
console.log(bookObj.author); // => 'F. Scott Fitzgerald'
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -28,14 +28,14 @@
|
|||||||
try {
|
try {
|
||||||
const response = await fetch('https://dummyjson.com/posts');
|
const response = await fetch('https://dummyjson.com/posts');
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('HTTP-Reponse Error');
|
throw new Error('HTTP-Response Error');
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
return data; // Rückgabe ist async -> Promise
|
return data; // Rückgabe ist async -> Promise
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fetch operation error: ', error);
|
// console.error('Fetch operation error: ', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user