Login blogger > pilih tata letak > tambah gadget >pilih HTML/javascript> lalu paste script di bawah ini di konten :
<script language="javascript">
var newdigit = true;
var op;
var temp;
function Angka(angka){
if(newdigit){
newdigit = false;
}else{
angka = document.kalkulator.layar.value + angka;
}
document.kalkulator.layar.value=angka;
}
function Operator(opt){
if(temp){
HitungLagi();
}
temp = document.kalkulator.layar.value;
op = opt;
newdigit=true;
}
function Hitung(){
var angka = document.kalkulator.layar.value;
if(op == 'x'){
temp = temp * angka;
}else if(op == ':'){
temp = temp / angka;
}else if(op == '+'){
temp = parseInt(temp) + parseInt(angka);
}else if(op == '-'){
temp = temp - angka;
}
document.kalkulator.layar.value = temp;
temp = 0;
}
function Reset(){
newdigit=true;
document.kalkulator.layar.value='HitungLagi';
temp=0;
}
</script>
<style type="text/css">
.button{
width:30px;
margin-top:6px;
}
.button-lebar{
width:64px;
margin-top:6px;
}
.button-lebar2{
width:132px;
margin-top:6px;
}
</style>
<form name="kalkulator">
<input type="text" value="0" name="layar" size="17" title="Angka 0"/><br
/>
<input type="button" value="7" class="button" onclick="Angka(7);"
title="Angka 7"/>
<input type="button" value="8" class="button" onclick="Angka(8);"
title="Angka 8"/>
<input type="button" value="9" class="button" onclick="Angka(9);"
title="Angka 9"/>
<input type="button" value="+" class="button" onclick="Operator('
+');" title="Menambahkan"/><br />
<input type="button" value="4" class="button" onclick="Angka(4);"
title="Angka 4"/>
<input type="button" value="5" class="button" onclick="Angka(5);"
title="Angka 5"/>
<input type="button" value="6" class="button" onclick="Angka(6);"
title="Angka 6"/>
<input type="button" value="-" class="button" onclick="Operator('-
');" title="Mengurangkan"/><br />
<input type="button" value="1" class="button" onclick="Angka(1);"
title="Angka 1"/>
<input type="button" value="2" class="button" onclick="Angka(2);"
title="Angka 2"/>
<input type="button" value="3" class="button" onclick="Angka(3);"
title="Angka 3"/>
<input type="button" value="x" class="button" onclick="Operator
('x');" title="Mengalikan"/><br />
<input type="button" value="0" class="button" title="Angka 0"/>
<input type="button" value="=" class="button-lebar" onclick="Hitung();"
title="Hasilnya"/>
<input type="button" value=":" class="button" onclick="operator
(':');" title="Membagikan"/><br />
<input type="button" value="Reset" class="button-lebar2" onclick="Reset
();" title="Mengulang seperti Awal (Hapus)"/>
</form>
lalu klik simpan.dan selesai .
Tidak ada komentar:
Posting Komentar