Share your repls and programming experiences

← Back to all posts
A simple calculator
sojs (295)

A normal calculator. That can do most mathematical functions such as sqrt() and can even run javascript if you enclose it with function(){ //code goes here }
Have fun!

Comments
hotnewtop
Highwayman (1443)

Are you sure it can’t

sojs (295)

@Highwayman I meant plain sqrt(); I tried Math.eval() and

with(math){
    eval(x)
}

but they both did not work

Highwayman (1443)

@sojs it’d more be like

...
const sqrt = Math.sqrt;
x = r("equation: ");
eval(x)
sojs (295)

@Highwayman That is genius. I never thought of that. Thanks!

sojs (295)

@Highwayman Actually, that will not work because eval() only evaluates code in the string and does not use or interact with variables in the global namespace.

Highwayman (1443)

@sojs are you sure? That’s the entire point of eval though. It does work, just try it.