Skip to content

Instantly share code, notes, and snippets.

@scottswaaley
Created August 3, 2016 17:19
Show Gist options
  • Save scottswaaley/493f67fc0bc7048a103fa5221623dbc0 to your computer and use it in GitHub Desktop.
Save scottswaaley/493f67fc0bc7048a103fa5221623dbc0 to your computer and use it in GitHub Desktop.
function doGet() {
var app = UiApp.createApplication().setTitle("The Math Machine");
app.setStyleAttribute('background', 'black');
var formPanel = app.createFormPanel();
var verticalPanel = app.createVerticalPanel();
var label1 = app.createLabel("First Number: ").setStyleAttribute('color', 'white');
var textBox1 = app.createTextBox().setName('textBoxResult1');
var label2 = app.createLabel("Second Number: ").setStyleAttribute('color', 'white');
var textBox2 = app.createTextBox().setName('textBoxResult2');
var lb = app.createListBox().setName('lb1').addItem('Addition').addItem('Subtraction').addItem('Multiplication');
var submitButton = app.createSubmitButton("Perform the Operation");
verticalPanel.add(label1).add(textBox1).add(label2).add(textBox2).add(lb).add(submitButton);
formPanel.add(verticalPanel);
app.add(formPanel);
return app;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
var operator = "";
var numFinal = 0;
switch(e.parameter.lb1)
{
case 'Addition':
operator = " + ";
numFinal = e.parameter.textBoxResult1 * 1 + e.parameter.textBoxResult2 * 1
break;
case 'Subtraction':
operator = " - ";
numFinal = e.parameter.textBoxResult1 * 1 - e.parameter.textBoxResult2 * 1
break;
case 'Multiplication':
operator = " x ";
numFinal = e.parameter.textBoxResult1 * 1 * e.parameter.textBoxResult2 * 1
break;
}
var label1 = app.createLabel(e.parameter.textBoxResult1 + operator + e.parameter.textBoxResult2 + " = " + numFinal)
.setStyleAttribute('color', 'white').setStyleAttribute('fontSize', '500%');
app.add(label1);
return app;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment