»
Tiếng AnhTiếng PhápTiếng Việt

In - Máy tính đa chức năng - JavaScriptBank.com

Phiên bản đầy đủ: jsB@nk » Tính toán » Máy tính » Máy tính đa chức năng
URL: https://www.javascriptbank.com/advanced-calculator.html

Máy tính đa chức năng © JavaScriptBank.comHiệu ứng tạo ra một máy tính đa chức nãng, ngoài các phép toán thông thường, máy tính còn có thể tính sin, cos, cãn thức...

Phiên bản đầy đủ: jsB@nk » Tính toán » Máy tính » Máy tính đa chức năng
URL: https://www.javascriptbank.com/advanced-calculator.html



JavaScript
<SCRIPT>LastOper     = '';TempVal      = 0;NewNum       = 'Y';Memval       = 0;Dotused      = "N";Curroption   = 4;Maxoption    = 19;FirstinXonY  = '';Statelements = [0];n            = 0;Ave          = 0;Max          = 1.1111111234;Min          = 1.1111111234;Dummymaxmin  = 1.1111111234;Sum          = 0;additionalfunctions = ["x^2", "2^x", "x^y", "x^3", " n!  ", "Log", " Pi ", " h ", "Tan", "Cot", "Sin", "Cos", "Add", "Sum", "Ave", "Max", "Min", " n ", "Clr St", "Sta"];  function backspace() {  strlen = document.calc.Results.value.length;  if (strlen > 1 && document.calc.Results.value != "0."){document.calc.Results.value =  document.calc.Results.value.substring(0,strlen-1);}  document.calc.EQ.focus();}function Onediv(){  if (document.calc.Results.value == '0.')  {     document.calc.Results.value = "Can't Devide By 0";  }   else  {    document.calc.Results.value = 1 / document.calc.Results.value;    NewNum = "Y";  }  document.calc.EQ.focus();}function MoreOptions(){  if (Curroption > Maxoption) {Curroption = 0;}  document.calc.opt1.value = additionalfunctions[Curroption++];  if (Curroption > Maxoption) {Curroption = 0;}  document.calc.opt2.value = additionalfunctions[Curroption++];  if (Curroption > Maxoption) {Curroption = 0;}  document.calc.opt3.value = additionalfunctions[Curroption++];  if (Curroption > Maxoption) {Curroption = 0;}  document.calc.opt4.value = additionalfunctions[Curroption++];  document.calc.EQ.focus();}function Advfunction(Pos){  Pos += Curroption;  Pos -= 4;  if (Pos < 0) {Pos = Maxoption + Pos;}  if (Pos == 0) {document.calc.Results.value *= document.calc.Results.value;}  if (Pos == 1) {                  Temp = 1;                  for (var I = 0 ;I < document.calc.Results.value; I++)                   {                   Temp *= 2;                  }                   document.calc.Results.value = Temp;                }  if (Pos == 2)  {                  if (FirstinXonY == '')                   {                    FirstinXonY = document.calc.Results.value;                  }                  else                  {                    Temp = FirstinXonY;                    for (var I = 1 ;I < document.calc.Results.value; I++)                     {                     Temp *= FirstinXonY;                    }                     document.calc.Results.value = Temp;                    FirstinXonY = '';                  }                }    if (Pos == 4){Temp = 0; for (var I = 1; I <= document.calc.Results.value;I++) {Temp += I} document.calc.Results.value = Temp;}   if (Pos == 6){document.calc.Results.value =  3.14159265359;}               if (Pos == 12)                {                 Statelements[++n] = document.calc.Results.value;                  Expres = "Sum = + +" + Sum + " + " + "+" + document.calc.Results.value;                 eval(Expres);                 Ave = Sum/n;                 Max = 1 * Max;                 Min = 1 * Min;                 if (Max < document.calc.Results.value || Max == Dummymaxmin) {Max = document.calc.Results.value;}                 if (Min > document.calc.Results.value || Min == Dummymaxmin) {Min = document.calc.Results.value;}                  }   if (Pos == 13){document.calc.Results.value = Sum;}    if (Pos == 14){document.calc.Results.value = Ave;}    if (Pos == 15){if (n > 0) {document.calc.Results.value = Max;}}    if (Pos == 16){if (n > 0) {document.calc.Results.value = Min;}}    if (Pos == 17){document.calc.Results.value = n;}    if (Pos == 18)                {                 Statelements = [0];                 n            = 0;                 Ave          = 0;                 Max          = 1.1111111234;                 Min          = 1.1111111234;                 Dummymaxmin  = 1.1111111234;                 Sum          = 0;                                 }   if (Pos == 19)                {                 if (n > 0)                 {                   myWindow = window.open("", "newwin", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=200,height=180,left=400,top=300");                   myWindow.document.open();                   myWindow.document.write("<HTML><HEAD>");                   myWindow.document.write("<TITLE>Statistics</TITLE>");                   myWindow.document.write("</HEAD><FORM><BODY BGCOLOR=#FFFFFF TEXT=black>\n<CENTER>");                   myWindow.document.write("<TABLE ALIGN=CENTER>");                   myWindow.document.write("<TR><TD><B>n</B></TD><TD>: "  , n  , "</TD></TR>");                   myWindow.document.write("<TR><TD><B>Sum</B></TD><TD>: ", Sum, "</TD></TR>");                   myWindow.document.write("<TR><TD><B>Ave</B></TD><TD>: ", Ave, "</TD></TR>");                   myWindow.document.write("<TR><TD><B>Max</B></TD><TD>: ", Max, "</TD></TR>");                   myWindow.document.write("<TR><TD><B>Min</B></TD><TD>: ", Min, "</TD></TR>");                   myWindow.document.write("</TABLE>");                   myWindow.document.write(" <BR><INPUT TYPE='SUBMIT' VALUE='OK' onClick='window.close()'</FORM>\n</CENTER>");                   myWindow.document.write("</BODY></HTML>");                   myWindow.document.close();                 }                 else                 {                   myWindow = window.open("", "newwin", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=200,height=180,left=400,top=300");                   myWindow.document.open();                   myWindow.document.write("<HTML><HEAD>");                   myWindow.document.write("<TITLE> No Statistics</TITLE>");                   myWindow.document.write("</HEAD><FORM><BODY BGCOLOR=#FFFFFF TEXT=BLACK>\n<CENTER>");                   myWindow.document.write("<U><B>No Statistics</B></U><BR><BR>You did not add any item<BR>to the statistics<BR>To add items, use The<BR>'Add' Button");                   myWindow.document.write("<BR><BR><INPUT TYPE='SUBMIT' VALUE='OK' onClick='window.close()'</FORM></CENTER>");                   myWindow.document.write("</BODY></HTML>");                   myWindow.document.close();                 }                }  NewNum = 'Y';}     function SQRT(){  document.calc.Results.value = sqrt( document.calc.Results.value);  NewNum = "Y";  document.calc.EQ.focus();}function Percent(){  document.calc.Results.value *= TempVal / 100;  Dotused = "N";  NewNum = "Y";  document.calc.EQ.focus();} function Oper(OP){  if (LastOper == "+")  {     num1 = document.calc.Results.value;     Command = eval ("'+' + num1 +  '+' + TempVal");     document.calc.Results.value= eval (Command);  }      if (LastOper == "-")  {     num1 = document.calc.Results.value;     Command = "(document.calc.Results.value = TempVal - num1)";     eval (Command);  }   if (LastOper == "*")  {     num1 = document.calc.Results.value;     Command = "(document.calc.Results.value = TempVal * num1)";     eval (Command);  }   if (LastOper == "/")  {    if (document.calc.Results.value == '0.')    {       document.calc.Results.value = "Can't Devide By 0";    }     else    {      num1 = document.calc.Results.value;      Command = "(document.calc.Results.value = TempVal / num1)";      eval (Command);    }  }  if (OP != "=") {   document.calc.oper.value = " " + OP; } else {   document.calc.oper.value =""; } NewNum = "Y"; LastOper = OP; TempVal = document.calc.Results.value ; document.calc.EQ.focus(); FirstinXonY = '';} function Analyzethis(Key){  if (Key >= "0" && Key <= "9" )  {    Digit(Key);  }  if (Key == "*" || Key == "-" || Key == "\\" || Key == "+" || Key == "=")  {    Oper(Key);  }  document.calc.EQ.focus();} function Memory(Mode){    if (Mode == "Clear")    {       document.calc.Mem.value="";       Memval = 0;         }     if (Mode == "Set")    {        document.calc.Mem.value = "M";        Memval = document.calc.Results.value;    }     if (Mode == "Add")    {        document.calc.Mem.value = "M";        Command = eval("'+' + document.calc.Results.value + '+' + Memval");        Memval = eval (Command);    }     if (Mode == "Read")    {        document.calc.Results.value = Memval;        NewNum = "Y";    }        document.calc.EQ.focus();}function Dot(){   if (NewNum == "Y")  {    document.calc.Results.value = "0.";    Dotused = "Y";    NewNum = "N";  }  if (Dotused == "N")  {    document.calc.Results.value += ".";    Dotused = "Y";  }              document.calc.EQ.focus();} function Changesign(){  document.calc.Results.value *= -1;  document.calc.EQ.focus();}function Digit(DG){  if (NewNum == "Y")   {    document.calc.Results.value=DG;    Dotused = "N";  }  else  {    document.calc.Results.value= document.calc.Results.value + DG;  }   if (document.calc.Results.value == '0')  {   document.calc.Results.value = '0.'  }  else  {   NewNum = "N";  }  document.calc.EQ.focus();}function Clear (Type){  document.calc.Results.value = '0.';   NewNum = 'Y';  if (Type == "ALL")  {     document.calc.oper.value ="";     LastOper = '';     TempVal = 0;  }  document.calc.EQ.focus();}</SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<BODY onload=document.calc.EQ.focus()><FORM name=calc><TABLE border=5>  <TBODY>  <TR>    <TD colSpan=6><INPUT align=right name=Results onfocus=this.blur() size=19       value=0.> <INPUT align=center name=oper onfocus=this.blur() size=1> </TD></TR>  <TR>    <TD align=middle><INPUT maxLength=1 name=Mem onfocus=this.blur() size=1></TD>    <TD align=middle colSpan=2><INPUT onclick=backspace() type=button value=BkSp></TD>    <TD align=middle colSpan=2><INPUT onclick="Clear('Res')" type=button value="  CE "></TD>    <TD   align=middle><INPUT onclick="Clear('ALL')" type=button value=" C "></TD></TR>  <TR>    <TD align=middle><INPUT onclick="Memory('Clear')" type=button value=MC></TD>    <TD     align=middle><INPUT name=D7 onclick=Digit(7) type=button value=" 7 "></TD>    <TD     align=middle><INPUT name=D8 onclick=Digit(8) type=button value=" 8 "></TD>    <TD align=middle><INPUT onclick=Digit(9) type=button value=" 9 "></TD>    <TD align=middle><INPUT onclick=" Oper('/') " type=button value=" / "></TD>    <TD align=middle><INPUT onclick=SQRT() type=button value=sqr></TD></TR>  <TR>    <TD align=middle><INPUT onclick="Memory('Read')" type=button value=MR></TD>    <TD align=middle><INPUT onclick=Digit(4) type=button value=" 4 "></TD>    <TD align=middle><INPUT onclick=Digit(5) type=button value=" 5 "></TD>    <TD align=middle><INPUT onclick=Digit(6) type=button value=" 6 "></TD>    <TD align=middle><INPUT onclick=" Oper('*')" type=button value=" * "></TD>    <TD align=middle><INPUT onclick=Percent() type=button value=" % "></TD></TR>  <TR>    <TD align=middle><INPUT onclick="Memory('Set')" type=button value=MS></TD>    <TD align=middle><INPUT onclick=Digit(1) type=button value=" 1 "></TD>    <TD align=middle><INPUT onclick=Digit(2) type=button value=" 2 "></TD>    <TD align=middle><INPUT onclick=Digit(3) type=button value=" 3 "></TD>    <TD align=middle><INPUT onclick="Oper('-')" type=button value=" - "></TD>    <TD align=middle><INPUT onclick=Onediv() type=button value=1/x></TD></TR>  <TR>    <TD align=middle><INPUT onclick="Memory('Add')" type=button value=M+></TD>    <TD align=middle><INPUT onclick=Digit(0) type=button value=" 0 "></TD>    <TD align=middle><INPUT onclick=Changesign() type=button value=+/-></TD>    <TD align=middle><INPUT onclick=Dot() type=button value="  . "></TD>    <TD align=middle><INPUT onclick=" Oper('+') " type=button value=" +"></TD>    <TD align=middle><INPUT name=EQ onclick=" Oper('=')" onkeypress="Analyzethis('1')" type=button value=" =  "></TD></TR></TBODY></TABLE><INPUT name=addfeatures onclick=MoreOptions() type=button value="More Options"> <TABLE border=0>  <TBODY>  <TR>    <TD></TD>    <TD>      <TABLE border=4>        <TBODY>        <TR>          <TD><INPUT name=opt1 onclick=Advfunction(0) onfocus=document.calc.EQ.focus() type=button value=x^2></TD>          <TD><INPUT name=opt2 onclick=Advfunction(1) onfocus=document.calc.EQ.focus() type=button value=2^x></TD>          <TD><INPUT name=opt3 onclick=Advfunction(2) onfocus=document.calc.EQ.focus() type=button value=x^y></TD>          <TD><INPUT name=opt4 onclick=Advfunction(3) onfocus=document.calc.EQ.focus() type=button value=x^3></TD></TR></TBODY></TABLE></TD>    <TD></TD></TR></TBODY></TABLE></FORM></body><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->