Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. var g_width = 3;
  2. var g_height = 3;
  3. var i_left = 80;
  4. var i_top = 80;
  5. var cur_xloc = i_left;
  6. var x_sep = 60;
  7. var num = 1;
  8. var cur_yloc = i_top;
  9. var y_sep = 60;
  10. //var store = 0;
  11.  
  12. var store1 = "";
  13. var store2 = "";
  14. var num1 = 0;
  15. var num2 = 0;
  16.  
  17. var operation = "";
  18.  
  19. for (var j = 0; j < g_height; j++) {
  20. for (var i = 0; i < g_width; i++) {
  21. button("id" + num, num);
  22. setProperty("id" + num, "background-color", "#ffc0cb");
  23. setProperty("id" + num, "text-color", "#8ABAD3");
  24. setPosition("id" + num, cur_xloc, cur_yloc, 40, 40);
  25. cur_xloc = cur_xloc + x_sep;
  26. num = num + 1;
  27. }
  28. cur_yloc = cur_yloc + y_sep;
  29. cur_xloc = i_left;
  30. }
  31.  
  32. //Code for the non-numerical buttons
  33.  
  34. onEvent("bPlus", "click", function() {
  35. num1 = getNumber("ta_result");
  36. operation = "+";
  37. });
  38. onEvent("bMinus", "click", function() {
  39. num1 = getNumber("ta_result");
  40. operation = "-";
  41. });
  42. onEvent("bMultiply", "click", function() {
  43. num1 = getNumber("ta_result");
  44. operation = "*";
  45. });
  46. onEvent("bDivide", "click", function() {
  47. num1 = getNumber("ta_result");
  48. operation = "/";
  49. });
  50.  
  51. onEvent("bEquals", "click", function() {
  52. num2 = getNumber("ta_result");
  53. if (operation == "+") {
  54. num1 = num1 + num2;
  55. } else if ((operation == "-")) {
  56. num1 = num1 - num2;
  57. } else if ((operation == "*")) {
  58. num1 = num1 * num2;
  59. } else {
  60. num1 = num1 / num2;
  61. }
  62. setText("ta_result",num1);
  63. store1 = "";
  64. store2 = "";
  65. operation = "";
  66.  
  67. });
  68.  
  69. onEvent("bClear", "click", clearNum);
  70.  
  71.  
  72. //Sets the Text Box to 0 when intizalizing
  73. setText("ta_result",num1);
  74.  
  75. onEvent("b_Start", "click", function() {
  76. setScreen("sc_calc");
  77. });
  78.  
  79. //Function to Assign Numbers
  80. function numOperate(n) {
  81. if (operation == "")
  82. {
  83. store1+=n;
  84. num1=store1;
  85. setText("ta_result", num1);
  86. } else {
  87. store2+=n;
  88. num2=store2;
  89. setText("ta_result", num2);
  90. }
  91. }
  92.  
  93. //Numbers
  94. onEvent("id0", "click", function() {numOperate(0)});
  95. onEvent("id1", "click", function() {numOperate(1)});
  96. onEvent("id2", "click", function() {numOperate(2)});
  97. onEvent("id3", "click", function() {numOperate(3)});
  98. onEvent("id4", "click", function() {numOperate(4)});
  99. onEvent("id5", "click", function() {numOperate(5)});
  100. onEvent("id6", "click", function() {numOperate(6)});
  101. onEvent("id7", "click", function() {numOperate(7)});
  102. onEvent("id8", "click", function() {numOperate(8)});
  103. onEvent("id9", "click", function() {numOperate(9)});
  104.  
  105. // Function for Clear Button
  106. function clearNum() {
  107. store1 = "";
  108. store2 = "";
  109. num1 = 0;
  110. num2 = 0;
  111. operation = "";
  112. setText("ta_result",num1);
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement