Hallo, mache gerade meine ersten lieben Erfahrungen mit Java. Es geht um einfache Berechnungen, wir haben 4 inputs und 4 Zahlen sollen wieder ausgegeben werden.
Ich hab mir das mit ein paar Tutorials und Beispielen so zusammengebastelt, aber es funzt jetzt noch nicht, und ich bin ein bisschen am Ende meiner Kräfte :)
falls das hier quatsch ist mit javascript bin ich ansonsten auch für alternative lösungen offen.
Ich hab mir das mit ein paar Tutorials und Beispielen so zusammengebastelt, aber es funzt jetzt noch nicht, und ich bin ein bisschen am Ende meiner Kräfte :)
Code:
<html>
<head>
<title>Dial Calculator</title>
</head>
<body>
<br>
This site calculates how you can solve the dials in 4 steps.<br>
This works for any input / starting combination.<br>
The target combination is 2-7-4-6.<br><br><br><br>
<form name="inputs" onsubmit="return calc()">
<table cellpadding="2" cellspacing="2" border="0" style="text-align: left; width: 300px;" >
<tbody>
<tr>
<td>Initial <b><font color="#FFFF00">yellow</font></b> (top floor) number:</td>
<td><input type="text" size="2" name="y" value=""></td>
</tr>
<tr>
<td>Initial <b><font color="#FF8000">orange</font></b> (2nd floor) number:</td>
<td><input type="text" size="2" name="o" value=""></td>
</tr>
<tr>
<td>Initial <b><font color="#0000FF">blue</font></b> (3rd floor) number:</td>
<td><input type="text" size="2" name="b" value=""></td>
</tr>
<tr>
<td>Initial <b><font color="#FF00FF">purple</font></b> (bottom floor) number:</td>
<td><input type="text" size="2" name="p" value=""></td>
</tr>
<tr>
<td><br><br><input type="submit">
<br><br><input type="reset"</td>
</tr>
</tbody>
</table>
</form>
<script type="text/javascript">
<!---
function calc()
{
//input check
res = true;
y = document.inputs.y.value;
o = document.inputs.o.value;
b = document.inputs.b.value;
p = document.inputs.p.value;
if(y < 0 || y > 9){res = false;}
if(o < 0 || o > 9){res = false;}
if(b < 0 || b > 9){res = false;}
if(p < 0 || p > 9){res = false;}
if(res == false){alert('Wrong input format');
return;}
//calculation
resy = 4 - y + b - p;
reso = -2 - b + p;
resb = 5 - o + y;
resp = 1 - p + o - y;
document.writeln("Hit yellow " + resy " times");
document.writeln("Hit orange " + reso " times");
document.writeln("Hit blue " + resb " times");
document.writeln("Hit purple " + resp " times");
return;
}
//-->
</script>
</body></html>
Zuletzt bearbeitet: