Hello there, I've cooked up a calculator that're purely coded with JavaScript. Since this is for exercise only & I don't think it'd fit inside Tutorials section, I think I'll put it here. It's for fun only, it's not a real code. However, if you encounter any problems, don't hesitate to report it here. It's also learning purpose for me lol.
Basically use the [ic]Calculator(number1,operator,number2);[/ic] to call the function. If you want to test it but you're not gonna putting it inside your server, simply put it inside your console.
Encountered bugs:
1. The calculator didn't return PI.
Fixed bugs:
1. You can now sum one number into another.
Basically use the [ic]Calculator(number1,operator,number2);[/ic] to call the function. If you want to test it but you're not gonna putting it inside your server, simply put it inside your console.
- Code:
[panda=js]function Calculator(num1,operator,num2) {
switch(operator.charAt(0)) {
case "+":
return eval(num1+num2);
break;
case "-":
return eval(num1-num2);
break;
case "*":
return eval(num1*num2);
break;
case "/":
if(num1>num2) { return eval(num1/num2); }else{ return eval(num2/num1); }
break;
case /PI|Pi|pi/.test(operator):
return Math.PI();
break;
}
}
Encountered bugs:
1. The calculator didn't return PI.
- Code:
[panda=js]Calculator("PI"); // returns undefined
Fixed bugs:
1. You can now sum one number into another.