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)
================================ */

View file

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

View file

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