»
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/scientific-calculator.html

Máy tính đa chức năng © JavaScriptBank.comHiệu ứng tạo một máy tính có chức năng tổ hợp, chỉnh hợp, tính góc theo radian.

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/scientific-calculator.html



JavaScript
<SCRIPT language=Javascript type=text/javascript>var isnn,isieif(navigator.appName=='Microsoft Internet Explorer') //If browser is Internet Explorer{  isie=true }if(navigator.appName=='Netscape')//If browser is Netscape{  isnn=true }function right(e) //to trap right mouse button clicks{if (isnn && (e.which == 3 || e.which == 2 ))return false;else if (isie && (event.button == 2 || event.button == 3)) {alert("Thank you for using this Calculator.");return false;}return true;}function key(k)   {if(isie) {if(event.keyCode==17 || event.keyCode==18 || event.keyCode==93) {alert("Thank you for using this Calculator.") return false; } }if(isnn){alert("Thank you for using this Calculator.") return false; }   }if (isnn) window.captureEvents(Event.KEYPRESS);  if (isnn) window.captureEvents(Event.MOUSEDOWN);if (isnn) window.captureEvents(Event.MOUSEUP);document.onkeydown=key;  document.onmousedown=right;document.onmouseup=right;window.document.layers=right;</SCRIPT><SCRIPT language=JavaScript><!--Hide Script from non-javascript enabled browsersvar _operatorAdd = falsevar _operatorMinus = falsevar _operatorMultiply = falsevar _operatorDivide = falsevar _operatorMod = falsevar _operatorClicked = false //Check if any operator sign(+,-,/,* etc.) has been clickedvar _operatorExponent = falsevar _operatorPermutation = falsevar _operatorCombination = falsevar _currentValuevar _trigonometryRadians = falsevar _mem1,_mem2,_mem3function display(butName){switch(butName){case "one": if (_operatorClicked){//If an operator has been clicked previously  document.formCalc.Result.value=""//Clear the entry box  document.formCalc.Result.value="1" _operatorClicked = false}elsedocument.formCalc.Result.value+="1"breakcase "two":if (_operatorClicked){//If an operator has been clicked previously  document.formCalc.Result.value=""//Clear the entry box  document.formCalc.Result.value="2"  _operatorClicked = false}elsedocument.formCalc.Result.value+="2"breakcase "three":if (_operatorClicked){//If an operator has been clicked previously  document.formCalc.Result.value=""//Clear the entry box  document.formCalc.Result.value="3"  _operatorClicked = false}else   document.formCalc.Result.value+="3"breakcase "four":if (_operatorClicked){//If an operator has been clicked previously  document.formCalc.Result.value=""//Clear the entry box  document.formCalc.Result.value="4"  _operatorClicked = false}elsedocument.formCalc.Result.value+="4"breakcase "five":if (_operatorClicked){//If an operator has been clicked previously  document.formCalc.Result.value=""//Clear the entry box  document.formCalc.Result.value="5"  _operatorClicked = false}elsedocument.formCalc.Result.value+="5"breakcase "six":if (_operatorClicked){//If an operator has been clicked previously  document.formCalc.Result.value=""//Clear the entry box  document.formCalc.Result.value="6"  _operatorClicked = false}elsedocument.formCalc.Result.value+="6"breakcase "seven":if (_operatorClicked){//If an operator has been clicked previously  document.formCalc.Result.value=""//Clear the entry box  document.formCalc.Result.value="7"          _operatorClicked = false}elsedocument.formCalc.Result.value+="7"breakcase "eight":if (_operatorClicked){document.formCalc.Result.value=""document.formCalc.Result.value="8"_operatorClicked = false}elsedocument.formCalc.Result.value+="8"breakcase "nine":if (_operatorClicked){document.formCalc.Result.value=""document.formCalc.Result.value="9"_operatorClicked = false}elsedocument.formCalc.Result.value+="9"breakcase "zero":if (_operatorClicked){document.formCalc.Result.value=""document.formCalc.Result.value="0"_operatorClicked = false}elsedocument.formCalc.Result.value+="0"breakcase "point":if (_operatorClicked){document.formCalc.Result.value=""document.formCalc.Result.value="."_operatorClicked = false}elsedocument.formCalc.Result.value+="."breakcase "plus":_operatorClicked = true _operatorAdd = true _operatorMinus = false_operatorMultiply = false_operatorDivide = false_operatorPermutation = false_operatorCombination = false_currentValue = document.formCalc.Result.valuebreakcase "minus":_operatorClicked = true _operatorMinus = true_operatorAdd = false_operatorMultiply = false_operatorDivide = false_operatorPermutation = false_operatorCombination = false_currentValue = document.formCalc.Result.valuebreakcase "times":_operatorClicked = true _operatorMultiply = true_operatorMinus = false_operatorAdd = false_operatorDivide = false_operatorPermutation = false_operatorCombination = false_currentValue = document.formCalc.Result.valuebreakcase "divide":_operatorClicked = true _operatorDivide = true _operatorMod = false_operatorMinus = false_operatorAdd = false_operatorMultiply = false_operatorPermutation = false_operatorCombination = false_currentValue = document.formCalc.Result.valuebreak    case "mod":_operatorClicked = true _operatorMod = true _operatorDivide = false_operatorMinus = false_operatorAdd = false_operatorMultiply = false_operatorPermutation = false_operatorCombination = false_currentValue = document.formCalc.Result.value   break case "power3":// raise to the power of three _currentValue = parseFloat(document.formCalc.Result.value)_operatorClicked = true document.formCalc.Result.value = _currentValue * _currentValue * _currentValue  break case "pi":_operatorClicked = true document.formCalc.Result.value = Math.PIbreak    case "sqrt":_operatorClicked = true _currentValue = document.formCalc.Result.valuedocument.formCalc.Result.value = Math.sqrt(parseFloat(_currentValue))breakcase "Mem1":_operatorClicked = trueif (document.formCalc.Mem1.value=="M1R"){//Memory Recall   document.formCalc.Result.value = _mem1      }   else //Memory Store   {    _mem1 = document.formCalc.Result.value    document.formCalc.Mem1.value = "M1R"    }breakcase "Mem2":_operatorClicked = trueif (document.formCalc.Mem2.value=="M2R"){//Memory Recall   document.formCalc.Result.value = _mem2     }   else //Memory Store   {    _mem2 = document.formCalc.Result.value    document.formCalc.Mem2.value = "M2R"    }breakcase "Mem3":_operatorClicked = trueif (document.formCalc.Mem3.value=="M3R"){//Memory Recall   document.formCalc.Result.value = _mem3      }   else //Memory Store   {    _mem3 = document.formCalc.Result.value    document.formCalc.Mem3.value = "M3R"    }break    case "inverse":    _currentValue = document.formCalc.Result.value_operatorClicked = true  if (_currentValue == 0){document.formCalc.Result.value="Error:division by 0"}elsedocument.formCalc.Result.value = (1/_currentValue)break       case "square":    _currentValue = document.formCalc.Result.value_operatorClicked = true document.formCalc.Result.value = _currentValue * _currentValue break       case "percent":   _secondValue=parseFloat(document.formCalc.Result.value)   _secondValue=parseFloat(_currentValue)*_secondValue/100   document.formCalc.Result.value = _secondValue   _operatorClicked = true  break   case "exponent": // x raised to the power of y_currentValue = document.formCalc.Result.valueif (_currentValue ==""){document.formCalc.Result.value ="no input"_operatorClicked = true }else {_operatorExponent = true _operatorClicked = true _operatorDivide = false _operatorMinus = false_operatorMod = false_operatorAdd = false_operatorMultiply = false_operatorPermutation = false_operatorCombination = false} break       case "negative":_currentValue = document.formCalc.Result.value_operatorClicked = trueif (_currentValue == ""){// do nothing } else_currentValue = parseFloat(_currentValue)*(-1)document.formCalc.Result.value = _currentValue break  case "ln": // natural log of a number _operatorClicked = true _currentValue = document.formCalc.Result.valueif (_currentValue ==""){document.all.Result.value ="no input"}else document.formCalc.Result.value = Math.log(parseFloat(_currentValue))break case "naturale": // raise e to the power of a number._operatorClicked = true_currentValue = document.formCalc.Result.valueif (_currentValue ==""){document.all.Result.value ="no input"}else document.formCalc.Result.value = Math.exp(_currentValue)breakcase "sine":_operatorClicked = true _currentValue = document.formCalc.Result.valueif (_currentValue ==""){document.formCalc.Result.value ="no input"}else {if (_trigonometryRadians)document.formCalc.Result.value = Math.sin(parseFloat(_currentValue))else    _currentValue = parseFloat(_currentValue) * trigConverter()   document.formCalc.Result.value = Math.sin(_currentValue)}break   case "cosine":_operatorClicked = true _currentValue = document.formCalc.Result.valueif (_currentValue ==""){document.formCalc.Result.value ="no input"}else {if (_trigonometryRadians)document.formCalc.Result.value = Math.cos(parseFloat(_currentValue))else    _currentValue = parseFloat(_currentValue) * trigConverter()   document.formCalc.Result.value = Math.cos(_currentValue)}break  case "tangent":_operatorClicked = true_currentValue = document.formCalc.Result.valueif (_currentValue ==""){document.formCalc.Result.value ="Invalid input"}else {if (_trigonometryRadians)document.formCalc.Result.value = Math.tan(parseFloat(_currentValue))else  _currentValue = parseFloat(_currentValue) * trigConverter() document.formCalc.Result.value = Math.tan(_currentValue)}break case "arcsine":_operatorClicked = true _currentValue = document.formCalc.Result.valueif (_currentValue ==""){document.formCalc.Result.value ="Invalid input"}else {if (_trigonometryRadians) document.formCalc.Result.value = Math.asin(parseFloat(_currentValue))else document.formCalc.Result.value = Math.asin(parseFloat(_currentValue)) * trigInverser()}break  case "arccosine":_operatorClicked = true_currentValue = document.formCalc.Result.valueif (_currentValue ==""){document.formCalc.Result.value ="no input" }else {if (_trigonometryRadians) document.formCalc.Result.value = Math.acos(parseFloat(_currentValue))else document.formCalc.Result.value = Math.acos(parseFloat(_currentValue))* trigInverser()}break case "arctangent":_operatorClicked = true_currentValue = document.formCalc.Result.valueif (_currentValue ==""){document.formCalc.Result.value ="no input" }else {if (_trigonometryRadians) document.formCalc.Result.value = Math.atan(parseFloat(_currentValue))else document.formCalc.Result.value = Math.atan(parseFloat(_currentValue))* trigInverser()}break    case "back": _currentValue = document.formCalc.Result.value_newValue = _currentValue.slice(0,_currentValue.length-1)document.formCalc.Result.value = _newValuebreakcase "radians": //trig functions in radiansdocument.formCalc.degrees.checked = false _trigonometryRadians = truebreakcase "degrees": //trig functions in degreesdocument.formCalc.radians.checked = false_trigonometryRadians = false breakcase "factorial":_currentValue = document.formCalc.Result.value_operatorClicked = true//Since cannot do factorial of a negative number and //factorial of a number bigger than 170 is too large for the Math objectif (_currentValue=="" || _currentValue < 0 || _currentValue >170){document.formCalc.Result.value ="Enter a number between 0-170"}elsedocument.formCalc.Result.value = factorial(_currentValue)breakcase "permutation":_operatorClicked = true _currentValue = parseInt(document.formCalc.Result.value)if (_currentValue < 0 || _currentValue =="" || _currentValue>170){    document.formCalc.Result.value="Enter number between 0-170"   }else_currentValue = document.formCalc.Result.value_operatorPermutation = true_operatorCombination = false_operatorDivide = false _operatorMod = false_operatorMinus = false_operatorAdd = false_operatorMultiply = falsebreakcase "combination":_operatorClicked = true _currentValue = parseInt(document.formCalc.Result.value)if (_currentValue < 0 || _currentValue =="" || _currentValue>170){    document.formCalc.Result.value="Enter number between 0-170"     }else _operatorPermutation = false_operatorCombination = true_operatorDivide = false _operatorMod = false_operatorMinus = false_operatorAdd = false_operatorMultiply = falsebreakcase "clearmem":// Clearing memory_mem1=""_mem2=""_mem3=""document.formCalc.Mem1.value="M1"document.formCalc.Mem2.value="M2"document.formCalc.Mem3.value="M3"breakcase "log":// log to base ten of a number_operatorClicked = true _currentValue = document.formCalc.Result.valueif (_currentValue ==""){document.all.Result.value ="no input"}elsedocument.formCalc.Result.value= log2base10(_currentValue)breakdefault:window.close()}}function calculate(){var _nextValue, _operationValue  if (_operatorAdd){ // the addition operator was clicked_currentValue = parseFloat(_currentValue)_nextValue = parseFloat(document.formCalc.Result.value)_operationValue = _currentValue + _nextValuedocument.formCalc.Result.value = _operationValue    }   if (_operatorMinus){ // the subtraction operator was clicked   _currentValue = parseFloat(_currentValue)_nextValue = parseFloat(document.formCalc.Result.value)_operationValue = _currentValue - _nextValuedocument.formCalc.Result.value = _operationValue   }   if (_operatorMultiply){ // the multiplication operator was clicked   _currentValue = parseFloat(_currentValue)_nextValue = parseFloat(document.formCalc.Result.value)_operationValue = _currentValue * _nextValuedocument.formCalc.Result.value = _operationValue   }   if (_operatorDivide){ // the division operator was clicked   _currentValue = parseFloat(_currentValue)_nextValue = parseFloat(document.formCalc.Result.value)_operationValue = _currentValue / _nextValuedocument.formCalc.Result.value = _operationValue   }   if (_operatorExponent){ // the exponent operator was clicked   _currentValue = parseFloat(_currentValue)   _nextValue = parseFloat(document.formCalc.Result.value)   _operationValue = Math.pow(_currentValue,_nextValue)   document.formCalc.Result.value = _operationValue}   if (_operatorMod){ // the mod operator was clicked   _currentValue = parseFloat(_currentValue)   _nextValue = parseFloat(document.formCalc.Result.value)   _operationValue = _currentValue % _nextValue   document.formCalc.Result.value = _operationValue   }   if (_operatorPermutation){// the permutation operator was clicked   _currentValue = parseInt(_currentValue)   _nextValue = parseInt(document.formCalc.Result.value)   document.formCalc.Result.value = permute(_currentValue,_nextValue)   }   if (_operatorCombination){// the combination operator was clicked   _currentValue = parseInt(_currentValue)   _nextValue = parseInt(document.formCalc.Result.value)   document.formCalc.Result.value = combine(_currentValue,_nextValue)   }   _operatorClicked=true }  function trigConverter(){//To convert an angle from degrees to radians var _multiplier    _multiplier = Math.PI/180   return _multiplier }  function trigInverser(){//To convert an angle from radians to degrees var _multiplier _multiplier = 180/Math.PI return _multiplier}function factorial(n){ // workout the factorial of a numberif (parseInt(n)==0 || parseInt(n)==1){ return 1 }else {return  parseInt(n) * factorial(parseInt(n)-1)   }}function permute(nValue,rValue){// workout permutation of a number on anotherif(nValue < rValue) {var mess="Sorry cannot perform that!"return mess}elsereturn factorial(nValue)/factorial(nValue - rValue)}function combine(nValue,rValue){ // workout combination of a number on anotherif(nValue < rValue) {var mess="Sorry cannot perform that!"return mess}elsereturn factorial(nValue)/(factorial(nValue - rValue)* factorial(rValue))}function log2base10(nValue){//Calculate log to base 10 of a numberreturn Math.log(nValue)/Math.log(10) }--></SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<TABLE style="WIDTH: 258px; HEIGHT: 179px" height=130 cellSpacing=1 cellPadding=1 width=260 align=center background="" border=0>  <TBODY>  <TR>    <TD>      <FORM name=formCalc action="" method=post>      <TABLE style="WIDTH: 241px; HEIGHT: 54px" cellSpacing=0 cellPadding=0       width=75 border=1>        <TBODY>        <TR>          <TD style="BACKGROUND-COLOR: darkblue">            <P align=center></P></TD>          <TD style="BACKGROUND-COLOR: darkblue">            <P align=left><FONT face=Verdana color=white size=2><STRONG>Kili Scientific Calculator</STRONG> </FONT></P></TD></TR>        <TR>          <TD><INPUT style="WIDTH: 50px; COLOR: blue" onclick="document.all.Result.value=''" type=button value=Clear name=clear></TD>          <TD>          <INPUT style="WIDTH: 187px; HEIGHT: 22px; TEXT-ALIGN: right"             disabled name=Result size="20"></TD></TR>        <TR>          <TD><INPUT style="WIDTH: 50px; COLOR: indigo" onclick=display(this.name) type=button value=Back name=back></TD>          <TD><INPUT             style="LEFT: 0px; WIDTH: 28px; COLOR: indigo; TOP: 0px; HEIGHT: 20px"             onclick=display(this.name) type=radio CHECKED value=0             name=degrees><LABEL></LABEL> <FONT size=1><FONT face="Arial Narrow"             color=darkslateblue>Degrees</FONT> </FONT><INPUT             style="WIDTH: 22px; COLOR: indigo; HEIGHT: 20px"             onclick=display(this.name) type=radio value=1 name=radians> <FONT             face="Arial Narrow" color=darkslateblue         size=1>Radians</FONT></TD></TR></TBODY></TABLE></TD></TR>  <TR>    <TD>      <TABLE style="WIDTH: 75px" cellSpacing=1 cellPadding=1 width=75         border=1><TBODY>        <TR>          <TD><INPUT style="WIDTH: 35px; COLOR: mediumblue" onclick=display(this.name) type=button value="  1  " name=one></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: mediumblue" onclick=display(this.name) type=button value="  2  " name=two></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: mediumblue" onclick=display(this.name) type=button value="  3  " name=three></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: mediumblue" onclick=display(this.name) type=button value="  0  " name=zero></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkred" onclick=display(this.name) type=button value="  +  " name=plus></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkred" onclick=display(this.name) type=button value="   /   " name=divide></TD></TR>        <TR>          <TD><INPUT style="WIDTH: 35px; COLOR: mediumblue" onclick=display(this.name) type=button value="  4  " name=four></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: mediumblue" onclick=display(this.name) type=button value="  5  " name=five></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: mediumblue" onclick=display(this.name) type=button value="  6  " name=six></TD>          <TD><INPUT style="FONT-WEIGHT: bold; WIDTH: 35px; COLOR: mediumblue; HEIGHT: 24px" onclick=display(this.name) type=button value="  .  " name=point></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkred" onclick=display(this.name) type=button value="   -  " name=minus></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkred" onclick=display(this.name) type=button value="mod " name=mod></TD></TR>        <TR>          <TD><INPUT style="WIDTH: 35px; COLOR: mediumblue" onclick=display(this.name) type=button value="  7  " name=seven></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: mediumblue" onclick=display(this.name) type=button value="  8  " name=eight></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: mediumblue" onclick=display(this.name) type=button value="  9  " name=nine></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkred; HEIGHT: 24px" onclick=display(this.name) type=button value="+/- " name=negative></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkred" onclick=display(this.name) type=button value="  *   " name=times></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkred" onclick=calculate() type=button value="   =  " name=equals></TD></TR>        <TR>          <TD><INPUT style="WIDTH: 35px; COLOR: darkgreen" onclick=display(this.name) type=button value=sqrt name=sqrt></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkgreen" onclick=display(this.name) type=button value="1/x " name=inverse></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkgreen; HEIGHT: 24px" onclick=display(this.name) type=button value="x^2 " name=square></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkgreen; HEIGHT: 24px" onclick=display(this.name) type=button value="x^3 " name=power3></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkgreen" onclick=display(this.name) type=button value=" x^y  " name=exponent></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: darkgreen" onclick=display(this.name) type=button value="  %  " name=percent></TD></TR>        <TR>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo" onclick=display(this.name) type=button value=sin name=sine></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo" onclick=display(this.name) type=button value="cos " name=cosine></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo; HEIGHT: 24px" onclick=display(this.name) type=button value="tan " name=tangent></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo; HEIGHT: 24px" onclick=display(this.name) type=button value=Asin name=arcsine></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo" onclick=display(this.name) type=button align=left value=Acos name=arccosine></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo" onclick=display(this.name) type=button value=Atan name=arctangent></TD></TR>        <TR>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo" onclick=display(this.name) type=button value=n! name=factorial></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo; HEIGHT: 24px" onclick=display(this.name) type=button value=" pi  " name=pi></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo" onclick=display(this.name) type=button value=" ln  " name=ln></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: black; HEIGHT: 24px" onclick=display(this.name) type=button value=M1 name=Mem1></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: black" onclick=display(this.name) type=button value=M2 name=Mem2></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: black" onclick=display(this.name) type=button value=M3 name=Mem3></TD></TR>        <TR>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo" onclick=display(this.name) type=button value=nPr name=permutation></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo; HEIGHT: 24px" onclick=display(this.name) type=button value=nCr name=combination></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo" onclick=display(this.name) type=button value=" e^x  " name=naturale></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: indigo; HEIGHT: 24px" onclick=display(this.name) type=button value=log name=log></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: black" onclick=display(this.name) type=button value=MC name=clearmem></TD>          <TD><INPUT style="WIDTH: 35px; COLOR: maroon" onclick=display(this.name) type=button value=Exit name=exit></TD></TR></TBODY></TABLE></FORM></TD></TR></TBODY></TABLE><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->