Getting Started: Javascript Functions:

10 downloads 181 Views 296KB Size Report
Assignment 4 Javascript Guide. CIS*1000*DE. This tutorial will help you with the creation of a simple calculator. The requirements for the assignment.
Assignment 4 Javascript Guide CIS*1000*DE This tutorial will help you with the creation of a simple calculator. The requirements for the assignment are outlined online and some of the functions provided may need to be changed.

Getting Started: The file that you need to download from the outline is called template.html. Please rename this file to calculator.html instead. The calculator only requires you to have 1 HTML file. Inside this HTML file, you will have the CSS styles and HTML code as well as the javascript code. The javascript goes between the following tags: ...

Javascript Functions: Function 'call_func()': This function is a function that executes the complex formulas (sin, cos, tan, sqrt, squared, factorial, pi). For each of the formulas (except for squared and factorial) the javascript built in functions are used. Since you are only required to have 4 mathematical functions, some of the functions listed below are not necessary. They are as follows: sin cos tan sqrt pi

Math.sin Math.cos Math.tan Math.sqrt Math.PI

For the formulas squared and factorial, we need to create our own functions that will solve for the number given. These are explained below.

Function 'square()': (only needed if you are using squared as one of your mathematical functions) This function returns the square of the number provided.

Function 'factorial()': (only needed if you are using factorial as one of your mathematical functions) This function returns the factorial of the number provided.

Function 'clear_equation()': This function removes the entire equation and sets the value to 0.

Function 'equation()': This function appends the button that was selected to the end of the current equation. The function will check to see if the input is a number and if the last number in the equation is 0. If it is, it will overwrite the zero.

Function 'solve()': This function uses the javascript function 'eval' and calculates the solution to what is contained in the equation bar.

Function 'remove()': This function removes the last item that has been added to the equation bar. The function checks multiple scenarios to ensure that the item is removed entirely.

HTML: For the HTML portion of the assignment, most of the work is done. You just need to call the correct functions based on the button that you choose to place in. Since you need only 4 complex functions, the HTML code will vary. Below are examples of what you can include.

For the 'call_func' buttons, you can replace the information in the () with the name of the function that you want to use. For example, if you wanted to use the cosine function, use the following: ....onclick="call_func (Math.cos)"...

The information above is designed to help you make the calculator work. The TA's and the professor all have office hours throughout the semester and are always willing to help with the assignments. Please do NOT leave this assignment to the end as it takes some time to get everything working. Good luck!