Any basic addition, subtraction, multiplication and division equation can be entered in the console or set to a variable:
var solve = (3 + 7) + 2 * 8 / 2 // 18
and correctly solved.
My code is not doing this. I believe it has something to do with the textarea. When I enter (3 + 7) + 2 * 8 / 2 it displays (3 + 7) + 2 * 8 / 2 (instead of 18). Note that my code doesn't have a solve button, it solves as the problem is entered.
Fiddle: http://jsfiddle.net/kt4SL/
HTML
<textarea cols="50" rows="10" id="pSolve"></textarea>
<div id="answer"></div>
JavaScript
var input = document.getElementById("pSolve");
input.onkeyup = function() {
// Solve the input
finalAnswer = pSolve.value;
// Display answer
answer.innerHTML = finalAnswer;
}
I tried this:
// Solve the input
finalAnswer = Number(pSolve.value);
thinking it would fix it but it didn't work. Instead nothing was displayed. What am I missing or doing wrong?