Like SystemiConnectFri 15 Oct 2021, 04:50
Auto Save MessagesLGforumFri 26 Feb 2021, 13:31
New tutorial questionTheCrowMon 15 Feb 2021, 08:12
Support iOS Emojis (and other platforms)LGforumSun 14 Feb 2021, 01:25
LGforum (2806)
Calculator function Vote_lcapCalculator function Voting_barCalculator function Vote_rcap 
Mr.Easybb (1587)
Calculator function Vote_lcapCalculator function Voting_barCalculator function Vote_rcap 
Bloodbath (745)
Calculator function Vote_lcapCalculator function Voting_barCalculator function Vote_rcap 
Rukiafan (533)
Calculator function Vote_lcapCalculator function Voting_barCalculator function Vote_rcap 
Dom (513)
Calculator function Vote_lcapCalculator function Voting_barCalculator function Vote_rcap 
puppycheese (446)
Calculator function Vote_lcapCalculator function Voting_barCalculator function Vote_rcap 
pedro (330)
Calculator function Vote_lcapCalculator function Voting_barCalculator function Vote_rcap 
Neymar (301)
Calculator function Vote_lcapCalculator function Voting_barCalculator function Vote_rcap 
Hitsu (281)
Calculator function Vote_lcapCalculator function Voting_barCalculator function Vote_rcap 
Flora (275)
Calculator function Vote_lcapCalculator function Voting_barCalculator function Vote_rcap 


Calculator function

Master TrollMaster Troll
Status : No status yet...

Posts : 9
Join date : 2016-06-18
Sun 19 Jun 2016, 10:05
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.

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.
evaleval
Status : No status yet...

Posts : 9
Join date : 2015-04-11
Mon 20 Jun 2016, 03:22
This lines is completely unnecessary:

Code:
[panda=js]return eval(num1-num2); // use return num1-num2 instead
return eval(num1*num2); // use return num1*num2 instead
if(num1>num2) { return eval(num1/num2); }else{ return eval(num2/num1); }
/* First. you'll better use this:
* condition ? expr1 : expr2;
* Second. use return num1/num2 instead
* Third. use return num2/num1 instead
*/
Master TrollMaster Troll
Status : No status yet...

Posts : 9
Join date : 2016-06-18
Mon 20 Jun 2016, 08:43
Alright.

Thanks for correcting. I'll update the post.
Master TrollMaster Troll
Status : No status yet...

Posts : 9
Join date : 2016-06-18
Wed 22 Jun 2016, 11:49
I'm planning to make a widget on this Smile if anyone interested you can reply on this topic so I'll work on it.
avatarGuest
Wed 22 Jun 2016, 12:20
You've got to hurry... > http://fmdesign.forumotion.com/t645-suggestion-create-a-calculator-widget Razz

Oh, and please do NOT use copyrighted material from other sites when you do Wink There are tons of examples out there on the net, using HTML, JS, jQuery and CSS, so pick a couple to write your own code for the widget and you should be good. I think it 'd be relatively easy for anyone to create a simple basic (non-scientific) calculator widget in an afternoon. Just be careful on the names you pick for the divs and elements. They should be unique and not already be in use by phpBB3, phpBB2, Invision or punBB.
Master TrollMaster Troll
Status : No status yet...

Posts : 9
Join date : 2016-06-18
Wed 22 Jun 2016, 13:03
Whoa! I didn't thought anybody'll interested on this simple code haha Very Happy

Of course, I'll only make a simple calculator with an input & a lot of buttons there. I'll make it easy to style so it wouldn't look so dumb. And yes, I'll do my best not to use unique IDs & classes. I'll make sure it'll be done on Friday. TY!
avatarGuest
Wed 22 Jun 2016, 13:18
Good. I'll see with what you come up with after the weekend. And, why not make 2 versions? A simple and a scientific one? A 'switch between both'-button maybe? Please remember most of us who use widgets just got 180 px. of space Wink

Btw, 'I'll do my best not to use unique IDs & classes' > 'I'll do my best to use unique IDs & classes'. Smile
Master TrollMaster Troll
Status : No status yet...

Posts : 9
Join date : 2016-06-18
Fri 24 Jun 2016, 06:39
Alright. I'll make a simple one asap, and for a scientific one... I'm not sure I can do it but I'll give it my best shot. I'll definitely come up with something later. Thanks! ^^
Master TrollMaster Troll
Status : No status yet...

Posts : 9
Join date : 2016-06-18
Tue 28 Jun 2016, 04:32
Hello!

Sorry for the delay. I'm pretty busy in a while, but I can come up with a simple one soon. I'll edit this post if I'm finished. Thanks!
Sponsored content