Parcourir la source

add punkterechner

rosenclosed il y a 2 ans
Parent
commit
1d4dd59a60
2 fichiers modifiés avec 129 ajouts et 0 suppressions
  1. 8 0
      pages/punkterechner/index.php
  2. 121 0
      src/script/punkterechner.js

+ 8 - 0
pages/punkterechner/index.php

@@ -0,0 +1,8 @@
+<script src="/src/script/punkterechner.js"></script>
+<h1>Punkterechner</h1>
+<p>Gib hier deine bisher gesammelten Punkte ein und erfahre, wie viel Geld du dir schon "erministriert" hast.</p>
+<br>
+<input type="number" name="punkte" id="punkte-input">
+<button type="submit" id="submit-btn">Los!</button>
+<br>
+<p>Du hast schon <span id="rechner-output">0.00</span>€ verdient!</p>

+ 121 - 0
src/script/punkterechner.js

@@ -0,0 +1,121 @@
+/* WENN SICH DIE SATZUNG ÄNDERT EINFACH DIESE KONSTANTEN ANPASSEN (ALLE WERTE IN EURO)*/
+const GRUNDBETRAG = 0.50;
+
+const BONUS_50_BIS_79 = 10.00;
+
+const BONUS_80_BIS_99 = 14.00;
+
+const BONUS_100_BIS_149 = 20.00;
+
+const BONUS_150_BIS_199 = 30.00;
+
+const BONUS_MEHR_ALS_200 = 40.00;
+
+const AB_100_DOPPELT = false;
+///////////////////////////////////////////////////////////////////////////////
+/* ALLES UNTER DIESER ZEILE NICHT ANFASSEN, AUSSER DU WEISST WAS DU TUST!!!! */
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+/* WIRKLICH NICHTS ANFASSEN!!!*/
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+const inputField = document.getElementById("punkte-input");
+const submitBtn = document.getElementById("submit-btn");
+const outputContainer = document.getElementById("rechner-output");
+
+const evaluateBonuses = (value) => {
+    if (value >= 200) {
+        return BONUS_MEHR_ALS_200;
+    } else if (value >= 150) {
+        return BONUS_150_BIS_199;
+    } else if (value >= 100) {
+        return BONUS_100_BIS_149;
+    } else if (value >= 80) {
+        return BONUS_80_BIS_99;
+    } else if (value >= 50) {
+        return BONUS_50_BIS_79;
+    } else if (value < 50) {
+        return 0.00;
+    }
+}
+
+submitBtn.addEventListener("click", (e) => {
+    let input = inputField.valueAsNumber;
+    console.debug(input);
+    let bonus = evaluateBonuses(input);
+    console.debug(bonus);
+    let result = 0.00;
+    if (AB_100_DOPPELT && input >= 100) {
+        result = 100 * GRUNDBETRAG;
+        input = input - 100;
+        result = result + (input * GRUNDBETRAG * 2);
+    } else {
+        result = input * GRUNDBETRAG;
+    }
+    result = result + bonus;
+    console.debug(result);
+    if (result.toString().includes(".")) {
+        result = result.toString().concat("0");
+    } else if (!result.toString().includes("NaN")) {
+        result = result.toString().concat(".00");
+    }
+    outputContainer.innerHTML = result;
+})