From 548360c3453c1fb87745c88f564711f3c19447d5 Mon Sep 17 00:00:00 2001 From: gauvainboiche Date: Thu, 10 Jul 2025 18:18:24 +0200 Subject: [PATCH] Adding the 'Sports stats' exercice but modified to mesopotamian gods --- _small_exercices/gods.js | 94 ++++++++++++++++++++++++++++++++++ _small_exercices/meal_maker.js | 42 +++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 _small_exercices/gods.js create mode 100644 _small_exercices/meal_maker.js diff --git a/_small_exercices/gods.js b/_small_exercices/gods.js new file mode 100644 index 0000000..5c8c62f --- /dev/null +++ b/_small_exercices/gods.js @@ -0,0 +1,94 @@ +// CLASS of gods +const god = { + _gods: [ + { + name: "Ea", + pantheon: "Mesopotamian", + domain: ["Intelligence", "Wisdom", "Knowledge"] + }, + { + name: "Shamash", + pantheon: "Mesopotamian", + domain: ["Sun"] + }, + { + name: "Nergal", + pantheon: "Mesopotamian", + domain: ["Death", "Hell"] + }, + { + name: "Ningirsu", + pantheon: "Mesopotamian", + domain: ["War"] + }, + { + name: "Aton", + pantheon: "Egyptian", + domain: ["Sun"] + } + ], + _battles: [ + { + opponent: "Asag", + warrior: "Ningirsu", + outcome: "Asag lose and his stone armies are dispersed.", + pantheon: "Mesopotamian", + }, + { + opponent: "Humbaba", + warrior: "Gilgamesh", + outcome: "Gilgamesh kills Humbaba with the help of Enkidu", + pantheon: "Mesopotamian", + } + ], + // GETTER for gods + get gods() { + return this._gods; + }, + // GETTER for battles + get battles() { + return this._battles; + }, + // METHOD for adding a god + addGod(newName, newDomain, newPantheon) { + let god = { + name: newName, + domain: newDomain, + pantheon: newPantheon + }; + this._gods.push(god); + }, + // METHOD for adding a battle + addBattle(newOpponent, newWarrior, newOutcome, newPantheon) { + let battle = { + opponent: newOpponent, + warrior: newWarrior, + outcome: newOutcome, + pantheon: newPantheon + }; + this._battles.push(battle); + }, + // METHOD for retrieving gods by domains + getGodsByDomain(domain) { + return this._gods.filter(god => god.domain.includes(domain)); + }, +}; + +/* + +// LOGGING of the first arrays in the god CLASS +console.log(god.battles); +console.log(god.gods); +// Adding a new god and logging the result of the method +god.addGod("Kishar", ["Earth"], "Mesopotamian"); +console.log(god.gods); +// Adding a new battle and logging the result of the method +god.addBattle("Tiamat", "Marduk", "Tiamat loses her fight against Marduk and her corpse become the sky and the soil.", "Mesopotamian"); +console.log(god.battles); + +*/ + +const godNames = god.gods.map(g => g.name); +const godDomains = god.gods.map(g => g.domain); +console.log(godNames); +console.log(godDomains); \ No newline at end of file diff --git a/_small_exercices/meal_maker.js b/_small_exercices/meal_maker.js new file mode 100644 index 0000000..011cdae --- /dev/null +++ b/_small_exercices/meal_maker.js @@ -0,0 +1,42 @@ +const menu = { + _meal: "", + _price: 0, + + set meal(mealToCheck) { + if (typeof mealToCheck === "string") { + this._meal = mealToCheck; + } else { + console.log('Please enter a valid string for the meal.'); + }, + + set price(priceToCheck) { + if (typeof priceToCheck === "number") { + this._price = priceToCheck; + } else { + console.log('Please enter a valid number for the price.'); + }, + + get todaysSpecial() { + if (this._meal && this._price) { + return(`Today's Special is ${this._meal} for ${this._price}€ !`); + } else { + return(`Meal or price was not set correctly.`) + } + } +}; + +menu.meal = "Enchiladas"; +menu.price = 15; +console.log(menu.todaysSpecial); + +menu.meal = "Hamburger savoyard"; +menu.price = 18; +console.log(menu.todaysSpecial); + +menu.meal = "Camembert au four"; +menu.price = "15"; +console.log(menu.todaysSpecial); // change the name of the plate but not the price + +menu.meal = true; +menu.price = "Canard laqué"; +console.log(menu.todaysSpecial); // doesn't change the name nor the price \ No newline at end of file