/************************************** * www.FemaleNerd.com * **************************************/ // Declare global variables var displayText = "" var num1 var num2 var operatorType // Write to display function addDisplay(n){ id = document.getElementById("display"); id.value = "" displayText += n id.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() { id = document.getElementById("display"); if (displayText == "") { num1 = result } else { num1 = parseFloat(displayText) } if (num1 != "") { result = Math.sin(num1) id.value = result displayText = "" } else { alert("Please write the number first") } } // Cosine function cos() { id = document.getElementById("display"); if (displayText == "") { num1 = result } else { num1 = parseFloat(displayText) } if (num1 != "") { result = Math.cos(num1) id.value = result displayText = "" } else { alert("Please write the number first") } } // ArcSine function arcSin() { id = document.getElementById("display"); if (displayText == "") { num1 = result } else { num1 = parseFloat(displayText) } if (num1 != "") { result = Math.asin(num1) id.value = result displayText = "" } else { alert("Please write the number first") } } // ArcCosine function arcCos() { id = document.getElementById("display"); if (displayText == "") { num1 = result } else { num1 = parseFloat(displayText) } if (num1 != "") { result = Math.acos(num1) id.value = result displayText = "" } else { alert("Please write the number first") } } // Square root function sqrt() { id = document.getElementById("display"); if (displayText == "") { num1 = result } else { num1 = parseFloat(displayText) } if (num1 != "") { result = Math.sqrt(num1) id.value = result displayText = "" } else { alert("Please write the number first") } } // Square number (number to the power of two) function square() { id = document.getElementById("display"); if (displayText == "") { num1 = result } else { num1 = parseFloat(displayText) } if (num1 != "") { result = num1 * num1 id.value = result displayText = "" } else { alert("Please write the number first") } } // Convert degrees to radians function degToRad() { id = document.getElementById("display"); if (displayText == "") { num1 = result } else { num1 = parseFloat(displayText) } if (num1 != "") { result = num1 * Math.PI / 180 id.value = result displayText = "" } else { alert("Please write the number first") } } // Convert radians to degrees function radToDeg() { id = document.getElementById("display"); if (displayText == "") { num1 = result } else { num1 = parseFloat(displayText) } if (num1 != "") { result = num1 * 180 / Math.PI id.value = result displayText = "" } else { alert("Please write the number first") } } // Calculations function calculate() { id = document.getElementById("display"); if (displayText != "") { num2 = parseFloat(displayText) // Calc: Addition if (operatorType == "add") { result = num1 + num2 id.value = result } // Calc: Subtraction if (operatorType == "subtract") { result = num1 - num2 id.value = result } // Calc: Multiplication if (operatorType == "multiply") { result = num1 * num2 id.value = result } // Calc: Division if (operatorType == "divide") { result = num1 / num2 id.value = result } displayText = "" } else { id.value = "Oops! Error!" } } // Clear the display function clearDisplay() { id = document.getElementById("display"); displayText = "" id.value = "" } EOT; \App::$page['htmlhead'] .= $x; } function get() { $o = ''; $o .= <<< EOT

Calculator



EOT; return $o; } }