-
Notifications
You must be signed in to change notification settings - Fork 0
Calculator
YuraVolk edited this page Dec 10, 2019
·
3 revisions
Calculator is a very useful programm. Even though it is very rarely used in sites, it still may be very useful.
If you want to implement this script by your own, follow these steps:
- Create array of operations.
- Add event listener for buttons.
- Create function of adding symbol, it should add new element to operations list.
- Create function of adding fraction, it should make number fractional.
- Add function for making number negative positive. It should add or remove '-' before number.
- Add function for adding prefix. It should wrap existing operation with passes parameters. For example:
param1 = Math.pow
param2 = ',2'
operations = ["2", '+', "2"]
Result: ["Math.pow(", "2", '+', "2", ",2)"]
- Add evaluate function. Make it check for XSS.
- Use eval with join;
- Add formatting for operations: format string as you want. Print its content to HTML.
If you have not read README.md, I highly urge you to do so. Wiki is in development currently