Calculate File
The calculate.js file is where all the action happens. The calculate file uses javascript. This is where you write the logic that performs the necessary transformations on your input to create your desired output. The calculate.js file must always return an output object based on the format specified below. The calculate.js file also handles all reporting functions, and returns the report that is generated by your calculator.
#
Layout#
Output Format#
ReportHelpersReportHelpers.round()
#
Will round any number to 2 decimal places, or if you provide a second argument it will round to that figure. It will work with strings and handle NaNs without crashing.
This will return a number back, that way you can continue to use this as a number (not a string)
#
ExamplesReportHelpers.convert()
#
Converts units
#
ExamplesReportHelpers.formula()
#
Will automatically evaluate and print an equation to represent the result.
ReportHelpers.formula(options)
#
Example#
Output
ReportHelpers.image()
#
Will print an image in the report
ReportHelpers.image(options)
#
ExampleReportHelpers.lineResult()
#
This will create a nice easy and lightweight reporting option. Rather than showing full equations, you might just want to print intermediate results:
ReportHelpers.formula(description, symbol, value)
Note: You will need to open a REPORT block for this to be visible:
#
Examples#
Output
ReportHelpers.quickTable()
#
#
Example#
Output
ReportHelpers.printStatus()
#
This will automatically format a clean colour-based result on the right side of the table. It will automaticall read a value, and if it is > 1 it will show a red FAIL. If it is < 1, it will show a green PASS:

#
Other PackagesThe following packages are also installed on the report by default:
- VariableCollection = calculate.js supports any variable functionality
- ResultsTable - create results tables
- SectionSVG = SVGs can be drawn using SkyCiv Section SVG Package (see dev-docs)
- Graph = (see dev-docs)
- JsToLatex = (see dev-docs)
- calculate = (see dev-docs)
#
How to Debug your CodeSince the code is running on our server (under a controlled environment) it may be difficult to debug. Errors are caught and returned to the user as a notification and in the actual report:

#
Logging:When you run your calculations, these will be available in the top corner of your code:

Having a detailed log will help both you and the user identify issues in the code:
