473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Make a JavaScript Calculator

Hey guys, I need to make a calculator
I have buttons for 0-9, digits = button, . button and have +, -, *, /, modules and square root operators and CE, M+, M- and backspace.
I have made the interface. Now all I want is make the javascript code.
It will be simple, I need a function for each and every operator. and also a switch case. can you guys plz help me??? thank you all..........
1 Minute Ago #1
Jan 4 '13 #1
6 2966
Use "eval()" function.
Each button writes his symbol in a textbox. Then evaluate the text entered using the eval function.
Try to start it
Jan 4 '13 #2
eval() function is quite easy to use !!
Jan 4 '13 #3
Dormilich
8,658 Expert Mod 8TB
eval() function is quite easy to use !!
eval() function is quite easy to abuse !!

if you’re not extremely careful, any attacker has your site in his hands.


PS. be aware of floating point arithmetics’ traps
Expand|Select|Wrap|Line Numbers
  1. // e.g.
  2. var sum = 0.1 + 0.2;
  3. alert(sum == 0.3);
Jan 4 '13 #4
acoder
16,027 Expert Mod 8TB
I need a function for each and every operator. and also a switch case.
What have you managed have so far? Give your attempt for, e.g., the + and = buttons. This will make it easier for someone to help you.
Jan 4 '13 #5
Anas Mosaad
185 128KB
eval() function is quite easy to abuse !!

if you’re not extremely careful, any attacker has your site in his hands.
Dormilich, just to remind you. JavaScript is client side. I don't believe that an attacker can do something harmful to his site with eval(). However, it's a good programming practice to handle all such issues.
Jan 5 '13 #6
@all Guys I don't need to use eval function. Teacher said don't use it.
here is my = function
Expand|Select|Wrap|Line Numbers
  1. function equals() {
  2. CurentDisplayValue = eval(document.frmOne.txtDisplay.value)
  3. PreviousDisplayValue = eval(total)
  4.  
  5. if(TheOperator =="+") {
  6.     answer = PreviousDisplayValue + CurentDisplayValue
  7. }
  8. else if(TheOperator == "*") {
  9.     answer = PreviousDisplayValue * CurentDisplayValue
  10. }
  11. else if(TheOperator == "-") {
  12.     tanswer = PreviousDisplayValue - CurentDisplayValue
  13. }
  14. else if(TheOperator == "/") {
  15.     answer = PreviousDisplayValue / CurentDisplayValue
  16. }
  17. document.frmOne.txtDisplay.value = answer
  18. }
how to create the equall buttun without eval?
Jan 8 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: mwh | last post by:
Hi. If you remember, I posted Expressons Help. Now I am making a calculator with javascript. I can't get this to work: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
3
by: Paul | last post by:
I want to make a simple calculator program but dont know where to get started. This is not GUI but a simple terminal program. It would get input like this Enter number: 5 + 10
4
by: 0to60 | last post by:
I'm trying to create a .dll with VS.NET 2003 Architect that contains a math computational component. I need the guts of the thing to be in native code, as performance is key for that part. But, I...
5
by: Steven Smith | last post by:
I was flicking through the windows accesories programs for some inspiration for todays vb challenge when I came accross the calculator program & thought that looks easy I could do that. However...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
1
by: gzeng | last post by:
Hi Everybdy: I am a beginner in C#. I'd like to write a simple online calculator in C#. This calculator will ask a user to input two numbers and then add them and display the result. So, it has...
5
Deathwing
by: Deathwing | last post by:
Hi everyone one I'm playing around with trying to make an expense calculator. I would like it so that the user can keep enter expenses until they have no more expenses. Then I would like for the...
2
by: frozenfirefly | last post by:
okay, so the first class of this program is the Fraction class. and which I supposed to create: 1. method to input numerator & denominator of fraction 2. and a method to reduce the fraction to its...
0
Curtis Rutland
by: Curtis Rutland | last post by:
Have any of you ever used a Reverse Polish Notation calculator? I did in high school. It was easily the best calculator ever (the HP=32SII). RPN is great, because you don't have to use parenthesis....
0
by: Laura Wilkinson | last post by:
Hello :), Basically, I am creating a website and the "frames" I've created are made from divs. I want to make my code, so that when a link in the left column is clicked, a different page, with the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.