Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var g_width = 3;
- var g_height = 3;
- var i_left = 80;
- var i_top = 80;
- var cur_xloc = i_left;
- var x_sep = 60;
- var num = 1;
- var cur_yloc = i_top;
- var y_sep = 60;
- //var store = 0;
- var store1 = "";
- var store2 = "";
- var num1 = 0;
- var num2 = 0;
- var operation = "";
- for (var j = 0; j < g_height; j++) {
- for (var i = 0; i < g_width; i++) {
- button("id" + num, num);
- setProperty("id" + num, "background-color", "#ffc0cb");
- setProperty("id" + num, "text-color", "#8ABAD3");
- setPosition("id" + num, cur_xloc, cur_yloc, 40, 40);
- cur_xloc = cur_xloc + x_sep;
- num = num + 1;
- }
- cur_yloc = cur_yloc + y_sep;
- cur_xloc = i_left;
- }
- //Code for the non-numerical buttons
- onEvent("bPlus", "click", function() {
- num1 = getNumber("ta_result");
- operation = "+";
- });
- onEvent("bMinus", "click", function() {
- num1 = getNumber("ta_result");
- operation = "-";
- });
- onEvent("bMultiply", "click", function() {
- num1 = getNumber("ta_result");
- operation = "*";
- });
- onEvent("bDivide", "click", function() {
- num1 = getNumber("ta_result");
- operation = "/";
- });
- onEvent("bEquals", "click", function() {
- num2 = getNumber("ta_result");
- if (operation == "+") {
- num1 = num1 + num2;
- } else if ((operation == "-")) {
- num1 = num1 - num2;
- } else if ((operation == "*")) {
- num1 = num1 * num2;
- } else {
- num1 = num1 / num2;
- }
- setText("ta_result",num1);
- store1 = "";
- store2 = "";
- operation = "";
- });
- onEvent("bClear", "click", clearNum);
- //Sets the Text Box to 0 when intizalizing
- setText("ta_result",num1);
- onEvent("b_Start", "click", function() {
- setScreen("sc_calc");
- });
- //Function to Assign Numbers
- function numOperate(n) {
- if (operation == "")
- {
- store1+=n;
- num1=store1;
- setText("ta_result", num1);
- } else {
- store2+=n;
- num2=store2;
- setText("ta_result", num2);
- }
- }
- //Numbers
- onEvent("id0", "click", function() {numOperate(0)});
- onEvent("id1", "click", function() {numOperate(1)});
- onEvent("id2", "click", function() {numOperate(2)});
- onEvent("id3", "click", function() {numOperate(3)});
- onEvent("id4", "click", function() {numOperate(4)});
- onEvent("id5", "click", function() {numOperate(5)});
- onEvent("id6", "click", function() {numOperate(6)});
- onEvent("id7", "click", function() {numOperate(7)});
- onEvent("id8", "click", function() {numOperate(8)});
- onEvent("id9", "click", function() {numOperate(9)});
- // Function for Clear Button
- function clearNum() {
- store1 = "";
- store2 = "";
- num1 = 0;
- num2 = 0;
- operation = "";
- setText("ta_result",num1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement