Javascript - Kvadratická rovnice
Napsal: sob 24. kvě 2008, 19:12
Napadlo mě vytvořit kvadratickou rovnici v Javascriptu a brzo jsem skončil, nevopočítá mi x1, x2, protože mi nebere Math.sqrt(D), jsem začátečník a nevím co stím. Poraďte někdo. Dík moc
<title>Kvadratická rovnice</title>
</head>
<body>
<h1>Řešení kvadratické rovnice</h1>
<script language="JavaScript">
a = parseFloat(window.prompt("Koeficient a",""));
b = parseFloat(window.prompt("Koeficient b",""));
c = parseFloat(window.prompt("Koeficient c",""));
var D, text;
D = (b*b)-(4*a*c);
text = "Diskriminant je";
document.write(text);
document.write(D);
if(D>0)
var x1, text;
x1 = ((-b)+Math.sqrt(D))/2*a;
text = "x1 je";
document.write(text);
document.write(x1);
if(D>0)
var x2, text;
x2 = ((-b)-Math.sqrt(D))/2*a;
text = "x2 je";
document.write(text);
document.write(x2);
{
}
</script>
</body>
</html>
<title>Kvadratická rovnice</title>
</head>
<body>
<h1>Řešení kvadratické rovnice</h1>
<script language="JavaScript">
a = parseFloat(window.prompt("Koeficient a",""));
b = parseFloat(window.prompt("Koeficient b",""));
c = parseFloat(window.prompt("Koeficient c",""));
var D, text;
D = (b*b)-(4*a*c);
text = "Diskriminant je";
document.write(text);
document.write(D);
if(D>0)
var x1, text;
x1 = ((-b)+Math.sqrt(D))/2*a;
text = "x1 je";
document.write(text);
document.write(x1);
if(D>0)
var x2, text;
x2 = ((-b)-Math.sqrt(D))/2*a;
text = "x2 je";
document.write(text);
document.write(x2);
{
}
</script>
</body>
</html>