From 80296c10d031fbb8a90ae2d198ab6fd0b5453cd1 Mon Sep 17 00:00:00 2001 From: Philippe Torrel Date: Mon, 28 Sep 2026 09:42:41 +0200 Subject: [PATCH] --- 02_advanced/uebungen/u20_geoquiz-2/index.html | 26 ++++++++++++-- .../uebungen/u21_pokemon-evolution/index.html | 35 ++++++++++++++++--- .../uebungen/u22_cocktail-mixing-2/index.html | 10 +++--- .../uebungen/u23_fetch-users/index.html | 26 +++++++++++++- .../uebungen/u24_obj-in-json/index.html | 4 ++- .../tag15/02_fetch-api-async-await/index.html | 4 +-- 6 files changed, 89 insertions(+), 16 deletions(-) diff --git a/02_advanced/uebungen/u20_geoquiz-2/index.html b/02_advanced/uebungen/u20_geoquiz-2/index.html index 1a5a0b9..2f4089c 100644 --- a/02_advanced/uebungen/u20_geoquiz-2/index.html +++ b/02_advanced/uebungen/u20_geoquiz-2/index.html @@ -1,4 +1,4 @@ - + @@ -35,7 +35,29 @@ ['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 diff --git a/02_advanced/uebungen/u21_pokemon-evolution/index.html b/02_advanced/uebungen/u21_pokemon-evolution/index.html index d8099a3..839ddd3 100644 --- a/02_advanced/uebungen/u21_pokemon-evolution/index.html +++ b/02_advanced/uebungen/u21_pokemon-evolution/index.html @@ -1,4 +1,4 @@ - + @@ -41,17 +41,42 @@ ['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(stagesAfter('Dratini')); // => [ 'Dragonair', 'Dragonite' ] + console.log(stagesAfter('Bulbasaur')); // => undefined + console.log(stagesAfter('Dragonite')); // => [] + console.log(stagesBefore('Pidgeot')); // => [ 'Pidgey', 'Pidgeotto' ] console.log(stagesBefore('Dragonair')); // => [ 'Dratini' ] - console.log(stagesBefore('Pidgey')); // => [ ] + + console.log(stagesBefore('Pidgey')); // => [] console.log(stagesBefore('Pidgeot')); // => ['Pidgey', 'Pidgeotto'] diff --git a/02_advanced/uebungen/u22_cocktail-mixing-2/index.html b/02_advanced/uebungen/u22_cocktail-mixing-2/index.html index 609f424..8a13259 100644 --- a/02_advanced/uebungen/u22_cocktail-mixing-2/index.html +++ b/02_advanced/uebungen/u22_cocktail-mixing-2/index.html @@ -1,4 +1,4 @@ - + @@ -64,19 +64,19 @@ 'Cucumber', ]; - const isMixableWithMyIngredients = (cocktailRecipe) => { - /* ??? */ + const isMixableWithMyIngredients = (cocktailRecipe, allIngredients = ingredientsFromMyBar) => { + return isMixableWith(cocktailRecipe, allIngredients); }; 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)); + console.log(cocktailRecipes.find((cocktailRecipe) => isMixableWithMyIngredients(cocktailRecipe))); // => [ 'Vodka', 'Lime Juice', 'Apple Juice', 'Cucumber' ] diff --git a/02_advanced/uebungen/u23_fetch-users/index.html b/02_advanced/uebungen/u23_fetch-users/index.html index 1d438d0..327bb95 100644 --- a/02_advanced/uebungen/u23_fetch-users/index.html +++ b/02_advanced/uebungen/u23_fetch-users/index.html @@ -1,4 +1,4 @@ - + @@ -25,6 +25,30 @@ diff --git a/02_advanced/uebungen/u24_obj-in-json/index.html b/02_advanced/uebungen/u24_obj-in-json/index.html index c2c0133..dc05968 100644 --- a/02_advanced/uebungen/u24_obj-in-json/index.html +++ b/02_advanced/uebungen/u24_obj-in-json/index.html @@ -41,9 +41,11 @@ F. Scott Fitzgerald }; // JSON String + const jsonString = JSON.stringify(book, null, 2); + console.log(jsonString); // JS Object - + const bookObj = JSON.parse(jsonString); console.log(bookObj.title); // => 'The Great Gatsby' console.log(bookObj.author); // => 'F. Scott Fitzgerald' diff --git a/02_advanced/unterricht/tag15/02_fetch-api-async-await/index.html b/02_advanced/unterricht/tag15/02_fetch-api-async-await/index.html index e2f4928..a11c58f 100644 --- a/02_advanced/unterricht/tag15/02_fetch-api-async-await/index.html +++ b/02_advanced/unterricht/tag15/02_fetch-api-async-await/index.html @@ -28,14 +28,14 @@ try { const response = await fetch('https://dummyjson.com/posts'); if (!response.ok) { - throw new Error('HTTP-Reponse Error'); + throw new Error('HTTP-Response Error'); } const data = await response.json(); return data; // Rückgabe ist async -> Promise } catch (error) { - console.error('Fetch operation error: ', error); + // console.error('Fetch operation error: ', error); throw error; }