Rabu, 13 Mei 2009

Calkulator


Membuat CaLculator dengan JavaScript 
Kali ini ada tugas pemrogaman web baru "rasa" java scrpit....:)

YuP mBuat CaLculator dengan Java Script (gag Pake' baterai....?!Hehe..:D)

Nie SkrinSYutnya..



dan ini SCRipTnya..




&lthtml&gt

&lthead&gt
&lttitle&gtJS - Calculator&lt/title&gt

&ltscript language="Javascript"&gt
&lt!--
/* Variable */
var plussign = ' + ';
var minussign = ' - ';
var multiplysign = ' * ';
var dividesign = ' / ';
var decimalsign = ' . ';
var negativesign = ' -';
var leftbracket = ' (';
var rightbracket = ') ';
var rad = 3.141592654 / 180;
var base_10 = Math.LN10;
var base_2 = Math.LN10;

/* Yup...Mulai */
function calculate(arg) {
arg.expr.value = eval(arg.expr.value)
}

function enter(arg, string) {
arg.expr.value += string
}

function clear_display(arg) {
arg.expr.value = ' '
}

function calc_sqrt(form) {
form.expr.value = (Math.sqrt(form.expr.value))
}

function calc_sqr(form) {
form.expr.value = ((form.expr.value * 1) * (form.expr.value * 1))
}

function sin_form(form) {
form.expr.value = (Math.sin (form.expr.value * rad))
}

function cos_form(form) {
form.expr.value = (Math.cos (form.expr.value * rad))


function tan_form(form) {
form.expr.value = (Math.tan(form.expr.value * rad))
}

function inverse(form) {
form.expr.value = ( 1 / (form.expr.value))
}

function base10_log(form) {
form.expr.value = (Math.log(form.expr.value) / base_10)
}

function base2_log(form) {
form.expr.value = (Math.log(form.expr.value) / base_2)
}
//--&gt
&lt/script&gt

&lt/head&gt

&ltbody&gt
&ltp align="center"&gt&ltbig&gt&ltbig&gtJavaScript - Calculator SMANEKA&lt/big&gt&lt/big&gt&lt/p&gt
&ltform&gt
&lt!-- Rechner Beginn --&gt
&lttable border="0" width="100" bgcolor="#CCCCCC" align="center"&gt
&lttr&gt
&lttd width="100%" colspan="5"&gt&ltinput type="text" name="expr" size="35"
action="calculate(this.form)"&gt&lt/td&gt
&lt/tr&gt
&lttr&gt
&lttd width="20%"&gt&ltinput type="button" value=" sin " Onclick="sin_form(this.form)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" cos " OnClick="cos_form(this.form)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" tan " Onclick="tan_form(this.form)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value="log10e" onClick="base10_log(this.form)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" log2e " OnClick="base2_log(this.form)"&gt&lt/td&gt
&lt/tr&gt
&lttr&gt
&lttd width="20%"&gt&ltinput type="button" value=" Sqrt " Onclick="calc_sqrt(this.form)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" Sqr " OnClick="calc_sqr(this.form)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" ( " OnClick="enter(this.form,
leftbracket)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" ) " OnClick="enter(this.form,
rightbracket)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" 1 / X " OnClick="inverse(this.form)"&gt&lt/td&gt
&lt/tr&gt
&lttr&gt
&lttd width="20%"&gt&ltinput type="button" value=" 7 " onClick="enter(this.form, 7)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" 8 " onClick="enter(this.form, 8)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" 9 " onClick="enter(this.form, 9)"&gt&lt/td&gt
&lttd width="40%" colspan="2"&gt&ltinput type="button" value=" C " onClick="clear_display(this.form)"&gt&lt/td&gt
&lt/tr&gt
&lttr&gt
&lttd width="20%"&gt&ltinput type="button" value=" 4 " onClick="enter(this.form, 4)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" 5 " onClick="enter(this.form, 5)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" 6 " onClick="enter(this.form, 6)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" * " onClick="enter(this.form,
multiplysign)"&gt &lt/td&gt
&lttd width="20%"&gt &ltinput type="button" value=" / " onClick="enter(this.form,
dividesign)"&gt&lt/td&gt
&lt/tr&gt
&lttr&gt
&lttd width="20%"&gt&ltinput type="button" value=" 1 " onclick="enter(this.form, 1)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" 2 " onclick="enter(this.form, 2)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" 3 " onclick="enter(this.form, 3)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" + " onClick="enter(this.form,
plussign)"&gt &lt/td&gt
&lttd width="20%"&gt &ltinput type="button" value=" - " onClick="enter(this.form,
minussign)"&gt
&lt/td&gt
&lt/tr&gt
&lttr&gt
&lttd width="20%"&gt&ltinput type="button" value=" 0 " onClick="enter(this.form, 0)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" . " onClick="enter(this.form,
decimalsign)"&gt&lt/td&gt
&lttd width="20%"&gt&ltinput type="button" value=" neg " onClick="enter(this.form,
negativesign)"&gt&lt/td&gt
&lttd width="40%" colspan="2"&gt&ltinput type="button" value=" = " onClick="calculate(this.form)"&gt&lt/td&gt
&lt/tr&gt
&lt/table&gt
&lt!-- Bisa... --&gt
&lt/form&gt
&lt/body&gt

&lt/html&gt



UpZs.....
ada perTanyaAnnya juga nie....
Eh JawaBannya juga..hoho..^^

1. Apa nama title skrip javascript tersebut ?
TitLenya : JS - Calculator

2. ekstensi file Skrip tersebut disimpan dengan file ber-ekstensi jenis ?
Skrip tersebut disimpan dengan file berekstensi jenis HTML (*.html/*.htm 

3. berapa jumlah variabel yang didefinisikan dalam file tersebut !
Jumlan variabelnya ada 11.

4. Berapa jumlah fungsi yang ada didalam skrip tersebut !
Jumlah fungsinya ada 11.

5. Tuliskan nama semua variabel skrip javascript tersebut ?

var plussign = ' + ';
var minussign = ' - ';
var multiplysign = ' * ';
var dividesign = ' / ';
var decimalsign = ' . ';
var negativesign = ' -';
var leftbracket = ' (';
var rightbracket = ') ';
var rad = 3.141592654 / 180;
var base_10 = Math.LN10;
var base_2 = Math.LN10; 


6. Tuliskan nama semua fungsi skrip tersebut ?

function calculate(arg)

function enter(arg, string)

function clear_display(arg)

function calc_sqrt(form)

function calc_sqr(form)

function sin_form(form)

function cos_form(form)

function tan_form(form)

function inverse(form)

function base10_log(form)

function base2_log(form)


7. Tuliskan skrip untuk membuat tampilan display pada skrip tersebut !

&ltinput type="text" name="expr" size="35"
action="calculate(this.form)"&gt


8. Tuliskan skrip untuk membuat 1 tombol !

&ltinput type="button" value=" sin " Onclick="sin_form(this.form)"&gt


9. Tuliskan fungsi jika tombol = ditekan oleh mouse !
&ltinput type="button" value=" = " onClick="calculate(this.form)"&gt

10. Tuliskan skrip untuk membersihkan display !
&ltinput type="button" value=" C " onClick="clear_display(this.form)"&gt

function clear_display(arg) {
arg.expr.value = ' '
}

Tidak ada komentar: