I have a basic Chrome App that I\'m building that constructs strings like this:
\"1 + 4 - 3 + -2\"
Seeing as you can\'t use eval()
eval()
Try modifying string to
"+1 +4 -3 -2"
utilizing String.prototype.split() , Array.prototype.reduce() , Number()
String.prototype.split()
Array.prototype.reduce()
Number()
var question = { text: "+1 +4 -3 -2", answer: function() { return this.text.split(" ") .reduce(function(n, m) { return Number(n) + Number(m) }) } }; console.log(question.answer())