Hallo elotse!
Unter Umständen bin ich etwas zu spät dran, mit meiner Hilfe. Aber hier eine if-else-Funktion, die ich selbst geschrieben habe, und funktioniert. Bin sehr stolz drauf.
Vielleicht hilft sie dir ja.
ZitatAlles anzeigen<!DOCTYPE html><html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function funk_gehalt(p_Umsatz, p_Bonus, p_Gehalt) {
var Umsatz = window.document.getElementById(p_Umsatz).value
var Grundgehalt = 1800
if (Umsatz < 10000)
{ Prozent = 0 }
else {
if (Umsatz < 20000)
{ Prozent = 2 }
else {
if (Umsatz < 30000)
{ Prozent = 3 }
else { Prozent = 5 }
}
}
Bonus = Umsatz*Prozent/100
Gehalt = Grundgehalt + Bonus
window.document.getElementById(p_Bonus).value = Bonus
window.document.getElementById(p_Gehalt).value = Gehalt
}
</script>
</head>
<body>
<h1>Zinsen</h1>
<table>
<tr>
<td>Umsatz: </td>
<td><input type="text" id="Umsatz"></td>
</tr>
<tr>
<td>Bonus: </td>
<td><input type="text" id="Bonus" readonly="readonly"></td>
</tr>
<tr>
<td>Gehalt: </td>
<td><input type="text" id="Gehalt" readonly="readonly"></td>
</tr>
</table>
<p><button type="button" onclick="funk_gehalt('Umsatz','Bonus','Gehalt');">Rechne!</button></p>
</body>
</html>
Unter anderem habe ich hier noch einen switch-case, den ich gerne präsentieren würde. Unter Umständen braucht ihn ja jemand. Auch hierauf bin ich sehr Stolz.
ZitatAlles anzeigen<!DOCTYPE html><html>
<head>
<meta charset="utf-8" />
<title>ES KLAPPT NET</title>
<script type="text/javascript">
function preisausgabe(p_alter, p_preis) {
alter=parseInt(window.document.getElementById(p_alter).value);
switch(true) {
case (alter < 3): preis = "Kostenlos"; break;
case (alter < 6) : preis = "1 Euro"; break;
case (alter < 12): preis = "2 Euro"; break;
case (alter < 16): preis = "3 Euro"; break;
case (alter > 16): preis = "4 Euro"; break;
default: preis = "ungültige Eingabe";break;}
window.document.getElementById(p_preis).value = preis
}
</script>
</head>
<body>
<table>
<tr>
<td>Eingabe des Alter</td>
<td><input type="text" id="f_alter"></td>
</tr>
<tr>
<td>Ausgabe des Preis</td>
<td><input type="text" id="f_preis" readonly=""></td>
</tr>
</table>
<button type="button" onClick="preisausgabe('f_alter','f_preis')">FERTIG</button>
</body>
</html>
Das war's dann aber ertmal von meiner Seite aus!
Ich hoffe sehr, dass ich damit dem ein oder anderen jungen Nachwuchsprogrammierer helfen konnte!
MFG Geblaten esse ich am liebsten.