PDA

View Full Version : Máy tính điện tử đa tính năng được lập bằng JavaScript



dokhoa
24-11-2010, 02:11 PM
Xin gửi tặng admin và các thành viên của diễn đàn Máy tính điện tử đa tính năng được lập bằng JavaScript.

Dưới đây là code mà mình đã kỳ công lập.
chúc các bạn vui vẻ trên diễn đàn.




<html> <head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Calculator - Trung tam 222a</title></head> <body style="text-align: center" bgcolor="#008080" bottommargin="0"> <div align="center"> <table cellpadding="0" bgcolor="#C0C0C0" border="2" bordercolor="#666666" style="padding-left: 4px; padding-right: 4px; padding-top: 0px; padding-bottom: 0px" width="596" height="246"> <!-- MSTableType="layout" --> <tr> <td width="590" height="240" align="center"><form name="bieumau"><p style="margin-top: 10px; margin-bottom: 4px"><i><b><font face="Arial" size="2">Trung tâm Tin học 222a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SuperCalculator 1.0</font></b></i></p><hr><p style="margin-top: 4px; margin-bottom: 4px"><font face="Arial" size="2">Input:&nbsp;&nbsp; </font>&nbsp;<input type="text" name="input" size="70"></p><p style="margin-top: 12px; margin-bottom: 16px"><font face="Arial" size="2">Output: </font> <input type="text" name="output" size="70"></p><p style="margin-top: 4px; margin-bottom: 4px"><input type="button" value="CE/OFF" style="width: 50px;height:24px; color:#FF0000; font-size:10px" onclick="ham('CE')" oncontextmenu="ham('OFF');return false"><input type="button" value="M+" style="width: 50px;height:24px; color:#0000FF; font-size:10px" onclick="hamnho(this.value)"><input type="button" value="M-" style="width: 50px;height:24px; color:#0000FF; font-size:10px" onclick="hamnho(this.value)"><input type="button" value="MR" style="width: 50px;height:24px; color:#0000FF; font-size:10px" onclick="hamnho(this.value)"><input type="button" value="MC" style="width: 50px;height:24px; color:#0000FF; font-size:10px" onclick="hamnho(this.value)">&nbsp;&nbsp;<input type="button" value="sin" style="width: 50px;height:24; font-size:10px" onclick="ham('Math.sin(')"><input type="button" value="asin" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.asin(')"><input type="button" value="cos" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.cos(')"><input type="button" value="acos" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.acos(')"><input type="button" value="tan" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.tan(')"></p><p style="margin-top: 4px; margin-bottom: 4px"> <input type="button" value="1" style="width: 50px;height:24px" onclick="ham(this.value)"><input type="button" value="2" style="width: 50px;height:24px" onclick="ham(this.value)"><input type="button" value="3" style="width: 50px;height:24px" onclick="ham(this.value)"><input type="button" value="4" style="width: 50px;height:24px" onclick="ham(this.value)"><input type="button" value="5" style="width: 50px;height:24px" onclick="ham(this.value)">&nbsp;&nbsp;<input type="button" value="atan" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.atan(')"><input type="button" value="atan2" style="width: 50;height:24; font-size:10px" onclick="ham('Math.atan2(')"><input type="button" value="log" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.log(')"><input type="button" value="LN2" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.LN2')"><input type="button" value="LN10" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.LN10')"></p><p style="margin-top: 4px; margin-bottom: 4px"><input type="button" value="6" style="width: 50px;height:24px" onclick="ham(this.value)"><input type="button" value="7" style="width: 50px;height:24px" onclick="ham(this.value)"><input type="button" value="8" style="width: 50px;height:24px" onclick="ham(this.value)"><input type="button" value="9" style="width: 50px;height:24px" onclick="ham(this.value)"><input type="button" value="0" style="width: 50px;height:24px" onclick="ham(this.value)">&nbsp;&nbsp;<input type="button" value="LOG2E" style="width: 50;height:24; font-size:10px" onclick="ham('Math.LOG2E')"><input type="button" value="LOG10E" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.LOG10E')"><input type="button" value="pow" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.pow(')"><input type="button" value="exp" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.exp(')"><input type="button" value="√" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.sqrt(')"></p><p style="margin-top: 4px; margin-bottom: 4px"><input type="button" value="." style="width: 50px;height:24px; font-size:10px" onclick="ham(this.value)"><input type="button" value="," style="width: 50px;height:24px; font-size:10px" onclick="ham(this.value)"><input type="button" value="(" style="width: 50px;height:24px; font-size:10px" onclick="ham(this.value)"><input type="button" value=")" style="width: 50px;height:24px; font-size:10px" onclick="ham(this.value)"><input type="button" value="%/Re" style="width: 50px;height:24px; font-size:10px; color:#000080" onclick="ham('/100')" oncontextmenu="ham('%');return false">&nbsp;&nbsp;<input type="button" value="| |" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.abs(')"><input type="button" value="floor" style="width: 50px;height:24; font-size:10px" onclick="ham('Math.floor(')"><input type="button" value="n!" style="width: 50px;height:24px; font-size:10px; color:#000080" onclick="hamgiaithua(1)"><input type="button" value="A!" style="width: 50px;height:24px; font-size:10px; color:#000080" onclick="hamgiaithua(2)"><input type="button" value="C!" style="width: 50px;height:24px; font-size:10px; color:#000080" onclick="hamgiaithua(3)"></p><p style="margin-top: 4px; margin-bottom: 4px"><input type="button" value="+" style="width: 50px;height:24px; font-size:10px" onclick="ham(this.value)"><input type="button" value="-" style="width: 50px;height:24px; font-size:10px" onclick="ham(this.value)"><input type="button" value="*" style="width: 50px;height:24px; font-size:10px" onclick="ham(this.value)"><input type="button" value="/" style="width: 50px;height:24px; font-size:10px" onclick="ham(this.value)"><input type="button" value="=" style="width: 50px;height:24px; font-size:10px" onclick="ham(this.value)">&nbsp;&nbsp;<input type="button" value="∑a" style="width: 50px;height:24px; font-size:10px; color:#000080" onclick="hamtinhtong(1)"><input type="button" value="∏a" style="width: 50px;height:24px; font-size:10px; color:#000080" onclick="hamtinhtong(2)"><input type="button" value="Mean" style="width: 50;height:24; font-size:10px; color:#000080" onclick="hamtrungbinh()"><input type="button" value="PI" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.PI')"><input type="button" value="E" style="width: 50px;height:24px; font-size:10px" onclick="ham('Math.E')"></p><p style="margin-top: 8px; margin-bottom: 4px"><input type="button" value="a" style="width: 36;height:24; font-size:10px" onclick="ham(this.value)"><input type="button" value="b" style="width: 36;height:24; font-size:10px" onclick="ham(this.value)"><input type="button" value="c" style="width: 36;height:24; font-size:10px" onclick="ham(this.value)"><input type="button" value="d" style="width: 36;height:24; font-size:10px" onclick="ham(this.value)"><input type="button" value="e/E" style="width: 36;height:24; font-size:10px" onclick="ham('e')" oncontextmenu="ham('E');return false"><input type="button" value="f" style="width: 36;height:24; font-size:10px" onclick="ham(this.value)"><input type="button" value="g/G" style="width: 36;height:24; font-size:10px" onclick="ham('g')" oncontextmenu="ham('G');return false"><input type="button" value="h" style="width: 36;height:24; font-size:10px" onclick="ham(this.value)"><input type="button" value="i/I" style="width: 36;height:24; font-size:10px" onclick="ham('i')" oncontextmenu="ham('I');return false"><input type="button" value="l/L" style="width: 36;height:24; font-size:10px" onclick="ham('l')" oncontextmenu="ham('L');return false"><input type="button" value="m/M" style="width: 36;height:24; font-size:10px" onclick="ham('m')" oncontextmenu="ham('M');return false"><input type="button" value="n/N" style="width: 36;height:24; font-size:10px" onclick="ham('n')" oncontextmenu="ham('N');return false"></p><p style="margin-top: 4px; margin-bottom: 8px"><input type="button" value="o/O" style="width: 36;height:24; font-size:10px" onclick="ham('o')" oncontextmenu="ham('O');return false"><input type="button" value="p/P" style="width: 36;height:24; font-size:10px" onclick="ham('p')" oncontextmenu="ham('P');return false"><input type="button" value="q/Q" style="width: 36;height:24; font-size:10px" onclick="ham('q')" oncontextmenu="ham('Q');return false"><input type="button" value="r/R" style="width: 36;height:24; font-size:10px" onclick="ham('r')" oncontextmenu="ham('R');return false"><input type="button" value="s/S" style="width: 36;height:24; font-size:10px" onclick="ham('s')" oncontextmenu="ham('S');return false"><input type="button" value="t/T" style="width: 36;height:24; font-size:10px" onclick="ham('t')" oncontextmenu="ham('T');return false"><input type="button" value="u" style="width: 36;height:24; font-size:10px" onclick="ham(this.value)"><input type="button" value="x" style="width: 36;height:24; font-size:10px" onclick="ham(this.value)"><input type="button" value="w" style="width: 36;height:24; font-size:10px" onclick="ham(this.value)"><input type="button" value="_" style="width: 36;height:24; font-size:10px" onclick="ham(this.value)"><input type="button" value="Math." style="width: 36;height:24; font-size:10px" onclick="ham(this.value)"><input type="button" value="&lt;---" style="width: 36;height:24; font-size:10px; color:#0000FF" onclick="hamxoa()"></p><p style="margin-top: 4px; margin-bottom: 4px"><input type="button" value="Ax+B = 0" style="width: 116;height:24; color:#000080" onclick="hamphuongtrinh(1)"><input type="button" value="Ax²+Bx+C = 0" style="width: 116;height:24; color:#000080" onclick="hamphuongtrinh(2)"><input type="button" value="Ax²+Bx+C &gt; 0" style="width: 116;height:24; color:#000080" onclick="hamphuongtrinh(3)"><input type="button" value="Ax²+Bx+C &lt; 0" style="width: 116;height:24; color:#000080" onclick="hamphuongtrinh(4)"></p><hr><p style="margin-top: 0px; margin-bottom: 0px"><font face="Arial" size="2">Khai thác JavaScript - Đỗ Minh Khoa - 18/09/2010 - kv_wizards@yahoo.com</font></p></form></td> </tr> </table></div> <script language="javascript">var ketqua=0;var biennho=0;var chuoinhap="";var chuoi=new String();function ham(thamso){if(thamso=="CE"){chuoinhap="";window.document.bieumau.input.value=""}else if(thamso=="OFF"){chuoinhap="";window.document.bieumau.input.value="";window.document.bieumau.output.value=""}else if(thamso=="="){ketqua=eval(window.document.bieumau.input.value) ;window.document.bieumau.output.value=ketqua}else{ chuoinhap=window.document.bieumau.input.value+tham so;chuoi=new String(chuoinhap);window.document.bieumau.input.va lue=chuoi};} function hamgiaithua(thamso){var nGT=1;var nkGT=1;var kGT=1;if(thamso==1){var n=prompt("Nhap so can tinh giai thua:","");if(n<0){alert("Dieu kien n>=0");return false};for(var i=1;i<=n;i++){nGT=nGT*i};ham(nGT)}else{var n=prompt("Nhap n:","");if(n<0){alert("Dieu kien n>=0");return false};var k=prompt("Nhap k (k<n):","");n=eval(n);k=eval(k);if(k<0){alert("Dieu kien k>=0");return false};if(k>n){alert("Dieu kien k<n");return false};for(var i=1;i<=n;i++){nGT=nGT*i}var nk=n-k;for(var j=1;j<=nk;j++){nkGT=nkGT*j}if(thamso==2){var Ank=nGT/nkGT;ham(Ank)};if(thamso==3){for(var h=1;h<=k;h++){kGT=kGT*h}var Cnk=nGT/(kGT*nkGT);ham(Cnk)};}} function hamphuongtrinh(thamso){if(thamso==1){var a=prompt("Nhap gia tri cho A:","");var b=prompt("Nhap gia tri cho B:","");a=eval(a);b=eval(b);if(a==0){alert("Dieu kien A khac 0!!!");return false}var x=-b/a;window.document.bieumau.output.value="Nghiem cua phuong trinh: x = "+x;ketqua=window.document.bieumau.output.value}els e{var a=prompt("Nhap gia tri cho A:","");var b=prompt("Nhap gia tri cho B:","");var c=prompt("Nhap gia tri cho C:","");a=eval(a);b=eval(b);c=eval(c);if(a==0){alert("Dieu kien A khac 0!!!");return false}var delta=b*b-4*a*c;if(thamso==2){if(delta<0){window.document.bieumau.output.value="Phuong trinh vo nghiem";ketqua=window.document.bieumau.output.value}else if(delta==0){var x=-b/2*a;window.document.bieumau.output.value="Phuong trinh co nghiem kep: x = "+x;ketqua=window.document.bieumau.output.value}els e{var x1=(-b+Math.sqrt(delta))/2*a;var x2=(-b-Math.sqrt(delta))/2*a;window.document.bieumau.output.value="Phuong trinh co 2 nghiem: x1 = "+x1+"; x2 = "+x2;ketqua=window.document.bieumau.output.value}}i f(thamso==3){if((a>0)&&(delta<0)){window.document.bieumau.output.value="Moi gia tri x deu la nghiem cua bat phuong trinh";ketqua=window.document.bieumau.output.value}else if((a>0)&&(delta==0)){var x0=-b/2*a;window.document.bieumau.output.value="Nghiem la moi gia tri x khac "+x0;ketqua=window.document.bieumau.output.value}el se if((a>0)&&(delta>0)){var x1=(-b+Math.sqrt(delta))/2*a;var x2=(-b-Math.sqrt(delta))/2*a;window.document.bieumau.output.value="Nghiem bat phuong trinh la: x < "+x2+"; x > "+x1;ketqua=window.document.bieumau.output.value}el se if((a<0)&&(delta<=0)){window.document.bieumau.output.value="Vo nghiem";ketqua=window.document.bieumau.output.value}else if((a<0)&&(delta>0)){var x1=(-b+Math.sqrt(delta))/2*a;var x2=(-b-Math.sqrt(delta))/2*a;window.document.bieumau.output.value="Nghiem nam trong khoang: "+x2+" < x < "+x1;ketqua=window.document.bieumau.output.value}}i f(thamso==4){if((a>0)&&(delta<=0)){window.document.bieumau.output.value="Vo nghiem";ketqua=window.document.bieumau.output.value}else if((a<0)&&(delta==0)){var x0=-b/2*a;window.document.bieumau.output.value="Nghiem la moi gia tri x khac "+x0;ketqua=window.document.bieumau.output.value}el se if((a>0)&&(delta>0)){var x1=(-b+Math.sqrt(delta))/2*a;var x2=(-b-Math.sqrt(delta))/2*a;window.document.bieumau.output.value="Nghiem nam trong khoang: "+x2+" < x < "+x1;ketqua=window.document.bieumau.output.value}el se if((a<0)&&(delta<0)){window.document.bieumau.output.value="Moi gia tri x deu la nghiem cua bat phuong trinh";ketqua=window.document.bieumau.output.value}else if((a<0)&&(delta>0)){var x1=(-b+Math.sqrt(delta))/2*a;var x2=(-b-Math.sqrt(delta))/2*a;window.document.bieumau.output.value="Nghiem bat phuong trinh la: x < "+x2+"; x > "+x1;ketqua=window.document.bieumau.output.value}}} } function hamtinhtong(thamso){ var sodau=prompt("nhap so dau cua chuoi:","");sodau=eval(sodau);var ketquatinh=0;var socuoi=prompt("nhap so cuoi cua chuoi:","");socuoi=eval(socuoi);if(thamso==1){for(var khoa=sodau;khoa<=socuoi;khoa++){ketquatinh=ketquatinh+khoa};ham(ke tquatinh)}if(thamso==2){ketquatinh=1;for(var khoa=sodau;khoa<=socuoi;khoa++){ketquatinh=ketquatinh*khoa};ham(ke tquatinh)}} function hamtrungbinh(){var mangTB=new Array();var soGT=prompt("Nhap so gia tri can tinh trung binh:","");soGT=eval(soGT);if(soGT<=1){alert("Phai nhap tu 2 so tro len");return false}var i=1;var tong=0;for(i=1;i<=soGT;i++){mangTB[i]=prompt("Nhap gia tri cho so thu "+i,"");tong=tong+eval(mangTB[i])}var ketquaTB=tong/soGT;ham(ketquaTB);} function hamxoa(){var vitrixoa=chuoi.length;vitrixoa--;chuoi=chuoi.substring(0,vitrixoa);window.document .bieumau.input.value=chuoi;chuoinhap=window.docume nt.bieumau.input.value;} function hamnho(thamso){if(thamso=="M+"){biennho=ketqua}else if(thamso=="M-"){biennho=ketqua*(-1)}else if(thamso=="MR"){window.document.bieumau.output.value=biennho}els e if(thamso=="MC"){biennho=0}}</script> </body> </html>