Script Kalkulator Sederhana :
<HTML>
<HEAD><TITLE>Kalkulator Sederhana</TITLE>
</HEAD>
<BODY bgcolor="#00CC00">
<div align="center">
<P><SCRIPT language="JavaScript">
<!--
function jumlah()
{
var bil1 = parseFloat(document.fform.bilangan1.value);
if (isNaN (bil1))
bil1=0.0;
var bil2 = parseFloat(document.fform.bilangan2.value);
if (isNaN (bil2))
bil2=0.0;
var hasil = bil1 + bil2;
alert ("Hasil Penjumlahan = " + hasil);
}
function kurang()
{
var bil1 = parseFloat(document.fform.bilangan1.value);
if (isNaN (bil1))
bil1=0.0;
var bil2 = parseFloat(document.fform.bilangan2.value);
if (isNaN (bil2))
bil2=0.0;
var hasil = bil1 - bil2;
alert ("Hasil Pengurangan = " + hasil);
}
function kali()
{
var bil1 = parseFloat(document.fform.bilangan1.value);
if (isNaN (bil1))
bil1=0.0;
var bil2 = parseFloat(document.fform.bilangan2.value);
if (isNaN (bil2))
bil2=0.0;
var hasil = bil1 * bil2;
alert ("Hasil Perkalian = " + hasil);
}
function bagi()
{
var bil1 = parseFloat(document.fform.bilangan1.value);
if (isNaN (bil1))
bil1=0.0;
var bil2 = parseFloat(document.fform.bilangan2.value);
if (isNaN (bil2))
bil2=0.0;
var hasil = bil1 / bil2;
alert ("Hasil Pembagian = " + hasil);
}
//--></SCRIPT></P>
<FORM NAME ="fform">
<center><h1>Kalkulator</h1>
<table style="font-family:verdana;font-size:10pt" align=center border=5 cellspacing=0>
</tr>
<tr>
<PRE>
<td colspan=2><input type="text" size="11" name="bilangan1"></td>
<td colspan=3><input type="text" size="11" name="bilangan2"></td>
</PRE>
</tr>
<tr align=center>
<td><INPUT TYPE="button" value="+" onClick="jumlah()"></td>
<td><INPUT TYPE="button" value="-" onClick="kurang()"></td>
<td><INPUT TYPE="button" value="x" onClick="kali()"></td>
<td><INPUT TYPE="button" value="/" onClick="bagi()"></td>
<td><INPUT TYPE="reset" value="Hapus"></td>
</FORM>
</br>
</div>
</BODY>
</HTML>
Tidak ada komentar:
Posting Komentar