Online Math Scripting Calculator: Safe Language with Loops, Functions & Plots
A built-in scripting lab for math and plotting. Write programs in a safe interpreted language (no eval) with variables, arrays, functions, loops and conditionals, plus built-in math, numerical derivative and integration functions and 2D/3D plotting commands. Run with Ctrl/Cmd+Enter, load example scripts, and see both console output and SVG/WebGL plots — all executed locally in your browser.
Script Calculator Guide
A safe sandbox language with variables, functions, loops and plots
The script calculator runs a small built-in language in a sandboxed interpreter. You can define variables and functions, use if/else branches, for and while loops, arrays (with range, push and len), call math built-ins, and generate 2D or 3D plots. The interpreter is parsed into an AST and executed entirely in your browser — it never uses eval or new Function, and a step limit prevents infinite loops.
01 Writing a script
Statements run top to bottom. Assign variables with =, define functions with fn name(args) { ... }, and branch with if/else. Loops use for (i = 0; i < n; i = i + 1) { ... } and while (cond) { ... }. Arrays are created with [1, 2, 3] or range(n), and push/len work as expected. print(...) writes to the output console.
Available math functions include sin, cos, tan, asin, acos, atan, log, exp, sqrt, abs, min, max, pow, floor, ceil and round, plus the constant pi. Plotting commands produce figures alongside the console: plot(f, xmin, xmax) for a 2D curve; plot3d(f, xmin, xmax, ymin, ymax) for a surface; param3d(x, y, z, tmin, tmax) for a parametric curve; and scatter3d(xs, ys, zs) for a point cloud. derivative(f, x) and integrate(f, a, b) are also provided.
Use the example buttons to load working samples, then edit them. Press Ctrl/Cmd+Enter (or Run) to execute. The editor inserts two spaces when you press Tab to keep indentation tidy. If a script contains an error, the console shows the line number and reason; if it runs too long, the step limit halts it safely.
- Variables: x = 3, name = value (no var/let keyword needed)
- Functions: fn add(a, b) { return a + b }
- Conditionals: if (x > 0) { ... } else { ... }
- Loops: for and while with braces around the body
- Arrays: [1, 2, 3], range(n), push(arr, v), len(arr)
- Output: print(...); plots render above the console
Running
- ▶ RunExecutes the script. Shortcut Ctrl/Cmd+Enter.
- Ctrl/Cmd+EnterKeyboard shortcut to run.
- TabInserts two spaces for indentation.
Example loaders
- 2DLoads a 2D plotting example using plot(...).
- 3DLoads a 3D surface example using plot3d(...).
- ParametricLoads a param3d(...) curve example.
- ScatterLoads a scatter3d(...) point-cloud example.
Editor and output
- code areaWrite your script here; line numbers are shown in the gutter.
- console panelShows print(...) output, error messages, or “No output”.
- plot areaRenders 2D/3D figures when the script calls a plot command.
Built-in commands
- plot(f, a, b)Draw a 2D curve of f(x) over [a, b].
- plot3d(f, a, b, c, d)Draw a surface z = f(x, y) over the rectangle.
- param3d(x, y, z, a, b)Draw a parametric curve over t ∈ [a, b].
- scatter3d(xs, ys, zs)Draw a 3D point cloud from three arrays.
- derivative(f, x)Numerical derivative of f at x.
- integrate(f, a, b)Numerical definite integral over [a, b].
- Always wrap function bodies and loop bodies in braces { }.
- Use print(...) to inspect values while debugging.
- The step limit protects the page from infinite loops — simplify heavy loops if halted.
- Start from an example and modify it to learn the syntax quickly.
- No DOM, network or eval access is available inside the sandbox — scripts cannot leave the browser.
A free online scripting calculator with a built-in safe language. Define variables and functions, use if/else, for and while loops, arrays and range/len/push, call math built-ins (sin, cos, log, sqrt, abs, min, max, pow), and generate plots with plot, plot3d, param3d and scatter3d. The interpreter is sandboxed — it never uses eval or new Function — and enforces a step limit. Press Ctrl/Cmd+Enter to run.
Writing a script
Statements run top to bottom. Assign variables with =, define functions with fn name(args) { ... }, and branch with if/else. Loops use for (i = 0; i < n; i = i + 1) { ... } and while (cond) { ... }. Arrays are created with [1, 2, 3] or range(n), and push/len work as expected. print(...) writes to the output console.
Math and plotting built-ins
Available functions include sin, cos, tan, asin, acos, atan, log, exp, sqrt, abs, min, max, pow, floor, ceil and round, plus the constant pi. Plotting commands: plot(f, xmin, xmax) for 2D; plot3d(f, xmin, xmax, ymin, ymax) for surfaces; param3d(x, y, z, tmin, tmax) for curves; scatter3d(xs, ys, zs) for point clouds. derivative(f, x) and integrate(f, a, b) are also provided.
Safety and limits
The language is parsed into an AST and interpreted in a sandbox with no access to the DOM, network or eval. An execution step limit prevents infinite loops, and memory is bounded. Press Ctrl/Cmd+Enter (or the Run button) to execute; errors show the line and reason in the console. All scripts stay in your browser.
FAQ
QIs the scripting language JavaScript?
No. It is a small custom language parsed into an AST and interpreted in a sandbox, with no DOM, network or eval access.
QHow do I run a script?
Press Ctrl/Cmd+Enter or click the Run button. Output from print(...) and any plots appear in the results area.
QWhat happens if I write an infinite loop?
The interpreter enforces a maximum execution step count and halts the script with an error, so the page will not freeze.
QCan I plot from a script?
Yes — use plot, plot3d, param3d and scatter3d; plots render alongside the console output. derivative(f,x) and integrate(f,a,b) are also available.