Scientific Calculator

Beyond basic arithmetic. This script exposes advanced mathematical functions for engineering and scientific calculations directly in the browser.

[Image of scientific calculator layout]

Copy the Script

<script>
function solve() {
    try {
        var val = document.getElementById("display").value;
        // Evaluate math string
        var res = eval(val);
        document.getElementById("display").value = res;
    } catch(e) {
        document.getElementById("display").value = "Error";
    }
}

function mathFunc(func) {
    var val = document.getElementById("display").value;
    // Apply Math.sin, Math.cos, etc.
    document.getElementById("display").value = Math[func](val);
}
</script>

Frequently Asked Questions

JavaScript's `Math.sin()` and `Math.cos()` use **radians** by default. To use degrees, you must convert the input: `radians = degrees * (Math.PI / 180)`.

Yes. You can use a global variable to store the value and add buttons to add/recall that variable.

It uses `eval()` or `Function constructor`. While powerful, `eval()` can be unsafe if not restricted. It is best to parse the string manually or ensure only valid math characters are allowed.