Adding Scientific Functions to a Web Page Calculator
Adding Scientific Functions to a Web Page Calculator - Coding Summary (Page 2 of 4 )
All of the scientific buttons have the onclick attribute. All of the buttons call one new function, which is the scienceFn() function. The ‘yx’ button calls our old operator() function. All of the scientific functions we are dealing with, except the one for ‘yx’, use only one value, namely, the number you type.
The ‘yx’ button does not use the scienceFn() function. When you type a number, and then press a scientific button, the scienceFn() function is called. The scienceFn() function has a switch statement, and each of its cases has a scientific function. So, after you have typed a number and clicked a scientific button, the corresponding scientific function uses the number typed as argument, and is executed. The scienceFn() function copies the result to the display.
The function for the ‘yx’ button needs two values for evaluation. Like the "+" operator, which needs two values for evaluation and uses the operator() function, when you click the ‘yx’ button, the operator() function is called. We shall see the details later. This is the skeleton of the scienceFn() function:
//give the sine of an angle
//give the tangent of an angle
//give the natural log of a number
//give log to base 10 of a number
//give the square root of a number
//give the square of a number
// Returns Eno., where number is the argument, and E is Euler's constant.
//round a number to the nearest integer.