/    Sign up×
Community /Pin to ProfileBookmark

calculator help please

i’ve designed a basic calculator and its working but not how i want it to. i’ve designed it (and dont want to change the design) so when the the user is inputting their calculation it all displays on the screen e.g. 1+3*5, now when someone puts a calculation in like that it does 3*5 then adds the 1 but i want it so it does the 1+3 first then multiplies by 5.

can anyone help?

thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Dec 07.2006 — alert(eval("1+3*5"));

alert(eval("(1+3)*
5"));

Eric
Copy linkTweet thisAlerts:
@supacook2kauthorDec 07.2006 — thanks for the reply but the function i have is

<i>
</i>function equals() {

document.calc.display.value=eval(document.calc.display.value);
}


is it possible to put it in the function?

is there a statement i can use to say do calculation from left to right?
Copy linkTweet thisAlerts:
@mjdamatoDec 07.2006 — To do what you want is probably going to take some string manipulation. Doing the calculation as you want is contrary to normal operation which is to compute multiplications & divisions then additions and subtractions working left to right. It is only when putting operators within parens that you can control the logic.
×

Success!

Help @supacook2k spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...