This commit is contained in:
Philippe Torrel
2026-09-21 10:31:46 +02:00
parent 12fdba3712
commit 6650b361c3
5 changed files with 102 additions and 32 deletions
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
@@ -28,7 +28,13 @@
<script>
'use strict';
const honoluluFlip = ['Maracuja Juice', 'Pineapple Juice', 'Lemon Juice', 'Grapefruit Juice', 'Crushed Ice'];
const honoluluFlip = [
'Maracuja Juice', //
'Pineapple Juice',
'Lemon Juice',
'Grapefruit Juice',
'Crushed Ice',
];
const ingredientsFromMyBar = [
'Pineapple',
@@ -49,17 +55,16 @@
// 1. Schreibe eine Funktion, `hasIngredient`, die `true` zurückgibt, wenn eine angegebene Zutat in einer Rezeptliste vorhanden ist. Rufe deine Funktion mit Maracujsasaft und Honolulu Flip auf.
const hasIngredient = (listOfIngredients, searchedIngredient) => {
/* ??? */
};
const hasIngredient = (listOfIngredients, searchedIngredient) => listOfIngredients.includes(searchedIngredient);
console.log(hasIngredient(honoluluFlip, 'Maracuja Juice')); // => true
// 2. So richtig sinnvoll ist unsere Funktion noch nicht. Viel hilfreicher wäre es, wenn wir eine Funktion hätten, die anhand unserer vorhandenen Zutaten herausfindet, ob wir den Cocktail auch tatsächlich machen können. Dafür benötigst du die komplette Liste aller bei dir vorhandenen Zutaten (ingredientsFromMyBar). Du möchtest wissen, ob du alle Zutaten vorrätig hast, die du zum Mixen des Cocktails benötigst.
const isMixableWith = (cocktailRecipe, availableIngredients) => {
/* ??? */
};
const isMixableWith = (cocktailRecipe, availableIngredients) =>
cocktailRecipe.every((ingredient) => hasIngredient(availableIngredients, ingredient));
//honoluluFlip isMixableWith ingredientsFromMyBar?
// honoluluFlip isMixableWith ingredientsFromMyBar?
console.log(isMixableWith(honoluluFlip, ingredientsFromMyBar)); // => true
</script>
</body>