Learn Create Your Own Split Screen

Next Page

Similarly, imagine you've keyed "100 + 32 - 1", but haven't yet pressed the "1" button.

At the moment you hit the minus key, the calculator actually adds the 100 and the 32.

If you have a real calculator nearby, try it — you might be surprised !

The first step in coding anything is to have a solid understanding of what needs to be done.

It turns out that when you press an operation button on a calculator, what happens is not that operator, but the one before. Don't believe it? Try it !

So we need to declare a variable that will keep track of the previous operator

var prev_op = "=";
(We initialise it as though the equal sign has just been pressed.)