function doOperator(var1, operator, var2) { switch(operator) { case "+": return var1 + var2; break; // etc.. } }