Now the important bit — handling operation keys.
- Store a copy of the currently displayed number in a variable called temp,
for convenience
- Depending on the previous operator, apply that number to the running_result variable
- If the equals button was pressed, display the running result
- Otherwise reset the display
- Remember which operator was pressed because it becomes the previous operator
function PressOperator (op) {
var temp = Number(numdisplay.innerText);
if (prev_op == "+") running_result += temp;
if (prev_op == "*") running_result *= temp;
if (prev_op == "/") running_result /= temp;
if (prev_op == "-") running_result -= temp;
if (prev_op == "=") running_result = temp;
if (op == "=") numdisplay.innerText = running_result;
else numdisplay.innerText="";
prev_op = op;
}