G
G
Gluck Virtualen2015-05-02 22:37:13
JavaScript
Gluck Virtualen, 2015-05-02 22:37:13

How to do calculations inside input in javascript?

The script takes a number from input, performs some calculations on it, and outputs the result.
It would be more convenient to fill this input with something like "16384 + 256" so that the script takes this amount and goes on working.
"But how, Holmes?" ©

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Zhak, 2015-05-02
@gluck59

The easiest option:

var value = '(5+7)*10';
var res = new Function('return ' + value);

console.log(res()) // => 210

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question