Submit templates for repl.it/templates here.

← Back to all posts
A Calculator Template!
Viper2211 (85)

What is it?

Well, it's my post for template jam.

How does it work?

The calculator works with a display, which has a value of a string. To call that value you just use calculator.display.value

It works all because of Javascript's nifty little eval()function. All it does it take the string and simplify it!

All the buttons just add to the string. An example is the 1 button below:

<tr> <input  value='1'  onclick="calculator.display.value+=1" > </tr>

The value tag is the number or symbol that is displayed on the calculator when the program is run.

Credits

Help - @TheTacticalCat

And don't forget to upvote!

Comments
hotnewtop
xxpertHacker (931)

Using eval() is considered to be among the worst coding practices in all of JavaScript, browser, Node, anywhere. I recommend making you're own expression parser and sanitizer.

Also, might I recommend a simple exponent operator, instead of ^2 and ^3.

Actually looking at the HTML further, you used inline script events, such as onclick, which is usually advised against, also, I'm pretty sure that prevent's Google's V8 from taking effect.

Viper2211 (85)

Oh wow. I never knew any of that. Thanks for the info. @StudentFires