notenrechnerdom

This commit is contained in:
annika koenig 2026-06-11 16:02:08 +02:00
parent 630fb14e61
commit 61c8a3b94c
3 changed files with 91 additions and 44 deletions

View file

@ -296,6 +296,38 @@ footer {
} }
} }
input#punkteInput {
padding: 12px 16px;
border-radius: 12px;
border: 2px solid rgba(0,0,0,0.1);
margin: 15px 0;
width: 220px;
font-size: 1rem;
}
#ergebnis {
margin-top: 15px;
font-weight: 600;
}
.progress-container {
width: 100%;
max-width: 300px;
height: 14px;
background: #eee;
border-radius: 20px;
overflow: hidden;
margin-top: 15px;
}
#progressBar {
height: 100%;
width: 0%;
transition: width 0.4s ease;
background: green;
border-radius: 20px;
}
/* ================================ /* ================================
DARK MODE (WICHTIG: AUSSERHALB MEDIA QUERY) DARK MODE (WICHTIG: AUSSERHALB MEDIA QUERY)
================================ */ ================================ */

View file

@ -1,43 +1,54 @@
// =============================== function berechneNote(p) {
// NOTENRECHNER if (p >= 90) return "sehr gut";
// =============================== if (p >= 75) return "gut";
if (p >= 60) return "befriedigend";
window.berechneNote = function (punkte) { if (p >= 50) return "ausreichend";
if (punkte >= 90) return "sehr gut";
if (punkte >= 75) return "gut";
if (punkte >= 60) return "befriedigend";
if (punkte >= 50) return "ausreichend";
return "nicht bestanden"; return "nicht bestanden";
};
function leseZahl(text) {
const eingabe = prompt(text);
if (eingabe === null || eingabe.trim() === "") return NaN;
return Number(eingabe.trim().replace(",", "."));
} }
window.startNotenrechner = function () { function getFarbe(note) {
const punkte = leseZahl("Wie viele Punkte hast du erreicht?"); switch (note) {
const max = leseZahl("Maximale Punktzahl?"); case "sehr gut":
case "gut":
return "green";
case "befriedigend":
return "orange";
case "ausreichend":
return "orangered";
default:
return "red";
}
}
if ( document.addEventListener("DOMContentLoaded", () => {
Number.isNaN(punkte) || const input = document.getElementById("punkteInput");
Number.isNaN(max) || const btn = document.getElementById("berechnenBtn");
max <= 0 || const output = document.getElementById("ergebnis");
punkte < 0 || const bar = document.getElementById("progressBar");
punkte > max
) { btn.addEventListener("click", () => {
alert("Bitte gültige Werte eingeben!"); const wert = parseFloat(input.value);
// VALIDIERUNG
const isValid =
!isNaN(wert) && wert >= 0 && wert <= 100;
input.style.borderColor = isValid ? "" : "red";
if (!isValid) {
output.textContent = "Bitte gültige Punkte (0100) eingeben!";
output.style.color = "red";
bar.style.width = "0%";
return; return;
} }
const prozent = (punkte / max) * 100; const note = berechneNote(wert);
const note = window.berechneNote(prozent); const farbe = getFarbe(note);
const text = `${punkte} von ${max} Punkten (${prozent.toFixed(1)}%) = ${note}`; output.textContent = `${wert}% = ${note}`;
output.style.color = farbe;
console.log(text); bar.style.width = wert + "%";
alert(text); bar.style.background = farbe;
}; });
});

View file

@ -33,18 +33,22 @@
<section class="hero"> <section class="hero">
<div class="hero-content"> <div class="hero-content">
<div class="hero-tag">📊 JavaScript Aufgabe</div> <div class="hero-tag">📊 DOM Notenrechner</div>
<h1>Noten<span>rechner</span></h1> <h1>Noten<span>rechner</span></h1>
<p> <p>Punkte eingeben und Note direkt auf der Seite erhalten.</p>
Hier kannst du Punkte eingeben und erhältst automatisch deine Note.
</p>
<div class="btn-group"> <input type="number" id="punkteInput" placeholder="Punkte (0100)" />
<button class="btn-primary" onclick="startNotenrechner()">
▶ Rechner starten <button class="btn-primary" id="berechnenBtn">
Berechnen
</button> </button>
<p id="ergebnis"></p>
<div class="progress-container">
<div id="progressBar"></div>
</div> </div>
</div> </div>
</section> </section>