- Langkah pertama buka aplikasi geany(contoh dari penulis) notepad juga bisa atau aplikasi lainnya
- Kemudian buat file baru lalu save beri nama penjumlahan.html
- Tulis kode di bawah ini :
<head>
<title>
</title>
<script type="text/javascript">
function lagi()
{
var a =document.getElementById('bil_a').value="";
var b =document.getElementById('bil_b').value="";
var c =document.getElementById('bil_c').value="";
var x1 =document.getElementById('x1').value="";
var x2 =document.getElementById('x2').value="";
var d =document.getElementById('hasil').value="";
var a = document.input.bil_a.focus();
}
function proses()
{
var a =document.getElementById('bil_a').value;
var b =document.getElementById('bil_b').value;
var c =document.getElementById('bil_c').value;
d = parseInt(b*b) - (4 * a * c);
document.getElementById('hasil').value= d;
if (a=="")
{
alert("nilai a belum diisi(Please check)");
var a = document.input.bil_a.focus();
var d =document.getElementById('hasil').value="";
var x1 =document.getElementById('x1').value="";
var x2 =document.getElementById('x2').value="";
}
else if (b=="")
{
alert("nilai b belum diisi(Please check)");
var b = document.input.bil_b.focus();
var d =document.getElementById('hasil').value="";
var x1 =document.getElementById('x1').value="";
var x2 =document.getElementById('x2').value="";
}
else if (c=="")
{
alert("nilai c belum diisi(Please check)");
var c = document.input.bil_c.focus();
var d =document.getElementById('hasil').value="";
var x1 =document.getElementById('x1').value="";
var x2 =document.getElementById('x2').value="";
}
else if (a==0)
{
alert("Nilai a = "+a+" bukan persamaan kuadrat");
var x1 =document.getElementById('x1').value="";
var x2 =document.getElementById('x2').value="";
var d =document.getElementById('hasil').value="";
var a = document.input.bil_a.focus();
var a =document.getElementById('bil_a').value="";
}
else if (d>0)
{
var x1 =(-b + Math.sqrt(d))/(2*a);
var x2 =(-b - Math.sqrt(d))/(2*a);
document.getElementById('x1').value=x1;
document.getElementById('x2').value=x2;
} else if (d==0)
{
var x1 =(-b - Math.sqrt(d))/(2*a);
document.getElementById('x1').value=x1;
document.getElementById('x2').value=x2;
} else if (d<0)
{
alert("Nilai Determinant = "+d+" akar-akarnya imaginer");
document.getElementById('x1').value="";
document.getElementById('x2').value="";
}
else if(a,b,c=isNaN)
{
alert("Nilai input tidak valid(harus integer)");
var a =document.getElementById('bil_a').value="";
var b =document.getElementById('bil_b').value="";
var c =document.getElementById('bil_c').value="";
var d =document.getElementById('hasil').value="";
var x1 =document.getElementById('x1').value="";
var x2 =document.getElementById('x2').value="";
var a = document.input.bil_a.focus();
}
}
</script>
</head>
<body onload="input.bil_a.focus()">
<H1 align="center" ><font color="olive">Program Mencari Persamaan Kuadrat </font></H1><BR>
<fieldset style="width: 50%; margin: auto;">
<LEGEND>Happy<font face="Comic Sans MS" color="olive" style="font-weight:bold;"> Coding </font></LEGEND>
<form id=input name=input>
Nilai a: <input type=text id=bil_a size=6 placeholder="Enter number" ><br>
Nilai b: <input type=text id=bil_b size=6 placeholder="Enter number"><br>
Nilai c: <input type=text id=bil_c size=6 placeholder="Enter number"><br>
</form>
<input type=button id=proses value=Hitung onclick='proses();'><br>
Nilai Determinan : <input type=text id=hasil size=6><br>
Nilai x1 : <input type=text id=x1 size=6><br>
Nilai x2 : <input type=text id=x2 size=6><br>
<label><font size=-1>klik »<input type=button id=proses value=Lagi onclick='lagi();'>untuk mengulang</font></label>
</FIELDSET>
</body>
</head>
</html>
Save kemudian buka file penjumlahan.html di browser (klik kanan dari file tersebut lalu pilih open with Firefox Web Browser seperti ini tampilannya:
semoga bermanfaat ya.Terimakasih.
Tidak ada komentar:
Posting Komentar