Gelişmiş Hesap Makinesi

<HTML>
<HEAD>
<TITLE>JavaScript Gelismis Hesap Makinesi</TITLE>
<SCRIPT LANGUAGE='JavaScript'>
var displayText = ""
var num1
var num2
var operatorType

// Write to display
function addDisplay(n){
document.calc.display.value = ""
displayText += n
document.calc.display.value = displayText
}

// Addition
function addNumbers() {
if (displayText == "") {
  displayText = result
 }
num1 = parseFloat(displayText)
operatorType = "add"
displayText = ""
}

// Subtraction
function subtractNumbers() {
if (displayText == "") {
  displayText = result
 }
num1 = parseFloat(displayText)
operatorType = "subtract"
displayText = ""
}

// Multiplication
function multiplyNumbers() {
if (displayText == "") {
  displayText = result
 }
num1 = parseFloat(displayText)
operatorType = "multiply"
displayText = ""
}

// Division
function divideNumbers() {
if (displayText == "") {
  displayText = result
 }
num1 = parseFloat(displayText)
operatorType = "divide"
displayText = ""
}

// Sine
function sin() {
if (displayText == "") {
  num1 = result
  }
else {
  num1 = parseFloat(displayText)
  }
if (num1 != "") {
  result = Math.sin(num1)
  document.calc.display.value = result
  displayText = ""
  }
else {
  alert("Önce bir numara yazınız")
  }
}

// Cosine
function cos() {
if (displayText == "") {
  num1 = result
  }
else {
  num1 = parseFloat(displayText)
  }
if (num1 != "") {
  result = Math.cos(num1)
  document.calc.display.value = result
  displayText = ""
  }
else {
  alert("Önce bir numara yazınız")
  }
}

// ArcSine
function arcSin() {
if (displayText == "") {
  num1 = result
  }
else {
  num1 = parseFloat(displayText)
  }
if (num1 != "") {
  result = Math.asin(num1)
  document.calc.display.value = result
  displayText = ""
  }
else {
  alert("Önce bir numara yazınız")
  }
}

// ArcCosine
function arcCos() {
if (displayText == "") {
  num1 = result
  }
else {
  num1 = parseFloat(displayText)
  }
if (num1 != "") {
  result = Math.acos(num1)
  document.calc.display.value = result
  displayText = ""
  }
else {
  alert("Önce bir numara yazınız")
  }
}

// Square root
function sqrt() {
if (displayText == "") {
  num1 = result
  }
else {
  num1 = parseFloat(displayText)
  }
if (num1 != "") {
  result = Math.sqrt(num1)
  document.calc.display.value = result
  displayText = ""
  }
else {
  alert("Önce bir numara yazınız")
  }
}

// Square number (number to the power of two)
function square() {
if (displayText == "") {
  num1 = result
  }
else {
  num1 = parseFloat(displayText)
  }
if (num1 != "") {
  result = num1 * num1
  document.calc.display.value = result
  displayText = ""
  }
else {
  alert("Önce bir numara yazınız")
  }
}

// Convert degrees to radians
function degToRad() {
if (displayText == "") {
  num1 = result
  }
else {
  num1 = parseFloat(displayText)
  }
if (num1 != "") {
  result = num1 * Math.PI / 180
  document.calc.display.value = result
  displayText = ""
  }
else {
  alert("Önce bir numara yazınız")
  }
}

// Convert radians to degrees
function radToDeg() {
if (displayText == "") {
  num1 = result
  }
else {
  num1 = parseFloat(displayText)
  }
if (num1 != "") {
  result = num1 * 180 / Math.PI
  document.calc.display.value = result
  displayText = ""
  }
else {
  alert("Önce bir numara yazınız")
  }
}

// Calculations
function calculate() {
if (displayText != "") {
  num2 = parseFloat(displayText)
// Calc: Addition
  if (operatorType == "add") {
    result = num1 + num2
    document.calc.display.value = result
    }
// Calc: Subtraction
  if (operatorType == "subtract") {
    result = num1 - num2
    document.calc.display.value = result
    }
// Calc: Multiplication
  if (operatorType == "multiply") {
    result = num1 * num2
    document.calc.display.value = result
    }
// Calc: Division
  if (operatorType == "divide") {
    result = num1 / num2
    document.calc.display.value = result
    }
  displayText = ""
  }
  else {
  document.calc.display.value = "Hata!"
  }
}
function clearDisplay() {
displayText = ""
document.calc.display.value = ""
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#9C6060">

<TABLE>
<TD> 
<TABLE BORDER=0 BGCOLOR="#AF9999">
<TD>
<TABLE border="0" cellpadding="2" cellspacing="2">
<FORM NAME=calc>
<TR>
	<TD COLSPAN=5><INPUT TYPE=text SIZE=22 NAME=display></TD>
<TR align="left" valign="middle">
	<TD><INPUT TYPE=button NAME="one" VALUE="   1   " onClick=addDisplay(1)></TD>
	<TD><INPUT TYPE=button NAME="two" VALUE="   2   " onClick=addDisplay(2)></TD>
	<TD><INPUT TYPE=button NAME="three" VALUE="   3   " onClick=addDisplay(3)></TD>
	<TD><INPUT TYPE=button NAME="plus" VALUE="   +   " onClick=addNumbers()></TD>
<TR align="left" valign="middle">
	<TD><INPUT TYPE=button NAME="four" VALUE="   4   " onClick=addDisplay(4)></TD>
	<TD><INPUT TYPE=button NAME="five" VALUE="   5   " onClick=addDisplay(5)></TD>
	<TD><INPUT TYPE=button NAME="six" VALUE="   6   " onClick=addDisplay(6)></TD>
	<TD><INPUT TYPE=button NAME="minus" VALUE="   -   " onClick=subtractNumbers()></TD>
<TR align="left" valign="middle">
	<TD><INPUT TYPE=button NAME="seven" VALUE="   7   " onClick=addDisplay(7)></TD>
	<TD><INPUT TYPE=button NAME="eight" VALUE="   8   " onClick=addDisplay(8)></TD>
	<TD><INPUT TYPE=button NAME="nine" VALUE="   9   " onClick=addDisplay(9)></TD>
	<TD><INPUT TYPE=button NAME="multiplication" VALUE="   *     " onClick=multiplyNumbers()></TD>
<TR align="left" valign="middle">
	<TD><INPUT TYPE=button NAME="zero" VALUE="   0   " onClick=addDisplay(0)></TD>
	<TD><INPUT TYPE=button NAME="pi" VALUE = "  Pi   " onClick=addDisplay(Math.PI)> </TD> 
	<TD><INPUT TYPE=button NAME="dot" VALUE="   .   " onClick=addDisplay(".")></TD>
	<TD><INPUT TYPE=button NAME="division" VALUE="   /   " onClick=divideNumbers()></TD>
<TR align="left" valign="middle">
	<TD><INPUT TYPE=button NAME="sqareroot" VALUE="sqrt" onClick=sqrt()></TD>
	<TD><INPUT TYPE=button NAME="squarex" VALUE=" x^2" onClick=square()></TD>
	<TD><INPUT TYPE=button NAME="deg-rad" VALUE="d2r  " onClick=degToRad()></TD>
	<TD><INPUT TYPE=button NAME="rad-deg" VALUE="r2d  " onClick=radToDeg()></TD>
<TR align="left" valign="middle">
	<TD><INPUT TYPE=button NAME="sine" VALUE="  sin  " onClick=sin()></TD>
	<TD><INPUT TYPE=button NAME="arcsine" VALUE="asin" onClick=arcSin()></TD>
	<TD><INPUT TYPE=button NAME="cosine" VALUE="cos" onClick=cos()></TD>
	<TD><INPUT TYPE=button NAME="arccosine" VALUE="acs" onClick=arcCos()></TD>

<TR align="left" valign="middle">
	<TD COLSPAN=2><INPUT TYPE=button NAME=clear VALUE="   Temizle   " onClick=clearDisplay()></TD>
	<TD COLSPAN=3><INPUT TYPE=button NAME=enter VALUE="      =      " onClick=calculate()></TD>

</TABLE>
</TABLE>


</TABLE>
</BODY>
</HTML>

 

Sizin Değerli Görüşlerinize İhtiyacımız Var.