Di seputar lingkungan kampus, kita sering mempelajari tentang pembuatan kalkulator dalam setiap materi praktek. Prinsipnya sama seperti di bahasa pemrograman C/C++ , Java, PHP, dan lainnya. Kini kita akan mengaplikasikan di Javascript. Disini kami menggunakan form, jadi kita bisa menginput value sesuai keinginan.
Berikut tampilan kalkulator dengan javascript
calculator javascript |
Bagi anda yang mau belajar, kami sertakan source code :
<html>
<head>
<title>Calculator Application Javascript</title>
<script type="text/javascript">
alert("Welcome to Calculator Application Javascript. Developper : pungki.it@gmail.com")
</script>
<script type="text/javascript">
function tambah()
{
var a,b,c;
a=document.forms[0].a.value;
b=document.forms[0].b.value;
c=parseInt(a)+parseInt(b);
document.forms[0].c.value=c;
}
function kurang()
{
var a,b,c;
a=document.forms[0].a.value;
b=document.forms[0].b.value;
c=parseInt(a)-parseInt(b);
document.forms[0].c.value=c;
}
function kali()
{
var a,b,c;
a=document.forms[0].a.value;
b=document.forms[0].b.value;
c=parseInt(a)*parseInt(b);
document.forms[0].c.value=c;
}
function bagi()
{
var a,b,c;
a=document.forms[0].a.value;
b=document.forms[0].b.value;
c=parseInt(a)/parseInt(b);
document.forms[0].c.value=c;
}
</script>
</head>
<body>
<form>
Nilai A <input type="text" name=a /><br />
Nilai B <input type="text" name=b /><br />
Hasil <input type="text" name=c /><br />
<input type="button" value="+" onclick="tambah()" />
<input type="button" value="-" onclick="kurang()" />
<input type="button" value="*" onclick="kali()" />
<input type="button" value="/" onclick="bagi()" /> <br />
<input type="reset" value="Reset" />
</form>
</body>
</html>
<head>
<title>Calculator Application Javascript</title>
<script type="text/javascript">
alert("Welcome to Calculator Application Javascript. Developper : pungki.it@gmail.com")
</script>
<script type="text/javascript">
function tambah()
{
var a,b,c;
a=document.forms[0].a.value;
b=document.forms[0].b.value;
c=parseInt(a)+parseInt(b);
document.forms[0].c.value=c;
}
function kurang()
{
var a,b,c;
a=document.forms[0].a.value;
b=document.forms[0].b.value;
c=parseInt(a)-parseInt(b);
document.forms[0].c.value=c;
}
function kali()
{
var a,b,c;
a=document.forms[0].a.value;
b=document.forms[0].b.value;
c=parseInt(a)*parseInt(b);
document.forms[0].c.value=c;
}
function bagi()
{
var a,b,c;
a=document.forms[0].a.value;
b=document.forms[0].b.value;
c=parseInt(a)/parseInt(b);
document.forms[0].c.value=c;
}
</script>
</head>
<body>
<form>
Nilai A <input type="text" name=a /><br />
Nilai B <input type="text" name=b /><br />
Hasil <input type="text" name=c /><br />
<input type="button" value="+" onclick="tambah()" />
<input type="button" value="-" onclick="kurang()" />
<input type="button" value="*" onclick="kali()" />
<input type="button" value="/" onclick="bagi()" /> <br />
<input type="reset" value="Reset" />
</form>
</body>
</html>
Selamat belajar. Terima kasih atas kunjungan anda
back link ke http://arfianhidayat.com disebelah mana ya?
ReplyDeletekalo udah ada nanti tak update link dari blogku kesini
Udah mas. silahkan, thanks
Delete