Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- var display = document.getElementById("prikaz");
- var up = document.getElementById("upis");
- var order = 0;
- var num1;
- var num2;
- var operation;
- function clearCalc()
- {
- num1 = "";
- num2 = "";
- order = 0;
- display.value = "";
- }
- function calcButton(button)
- {
- //operacije =10, /11, *12, -13, +16
- if(button < 10)
- {
- if(order == 0)
- {
- order = 1;
- display.value = "";
- }
- AddNumber(button);
- }
- else
- {
- // klik gumba
- if(order==1)
- {
- display.value = "";
- order=2;
- }
- if(button == 10)
- Operation();
- else
- operation = button;
- }
- }
- function AddNumber(num)
- {
- display.value += num;
- if(order == 1)
- {
- // postavljanje prvog broja
- num1=display.value;
- }
- else
- {
- // postavljanje drugog broja
- num2=display.value;
- }
- }
- function Operation()
- {
- switch(operation)
- {
- case 11: display.value = parseInt(num1) / parseInt(num2);break;
- case 12: display.value = parseInt(num1) * parseInt(num2);break;
- case 13: display.value = parseInt(num1) - parseInt(num2);break;
- case 14: display.value = parseInt(num1) + parseInt(num2);break;
- default: break;
- }
- order = 0;
- num1 = 0;
- num2 = 0;
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement