Actually, doing all this makes no sense at all, because JavaScript already can execute any text which is entered by a user, as a script, and show the result. This is done by the function
eval
. That's nearly all you need. If you want, check up how my calculator works:
http://sakryukov.org/freeware/calculator/[
^].
—SA