Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Javascript, isolated calculation
Old 01-20-2010, 09:24 AM Javascript, isolated calculation
Experienced Talker

Posts: 42
Name: Chansen
Trades: 0
Still fairly new to javascript, I have found out that it is not possible to use ( ) in variables. Correct?

But I want to do a calculation in a variable that goes likes this (example) 140625-(530*12), and the answer should be 134265.

Without ( ) it would go something like this (1st calculation) 530*12=6360 and then (2nd calculation) 140625-6360=134265.

What would a master do, and what do I do, to solve this little problem?
Chansen is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-20-2010, 09:33 AM Re: Javascript, isolated calculation
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I have found out that it is not possible to use ( ) in variables. Correct?
Nope


let's see ALL the code.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-20-2010, 10:12 AM Re: Javascript, isolated calculation
Experienced Talker

Posts: 42
Name: Chansen
Trades: 0
At given time I cannot show ALL code, however this is my variable...

var total = 140625-(530*12);

document.getElementById("total").innerHTML = total;


all my other calculated variables works like a dream, just not this one with ( ) which gives THE wrong answer...
Chansen is offline
Reply With Quote
View Public Profile
 
Old 01-20-2010, 10:42 AM Re: Javascript, isolated calculation
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
works Ok for me

what answer do you get?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-20-2010, 12:04 PM Re: Javascript, isolated calculation
Experienced Talker

Posts: 42
Name: Chansen
Trades: 0
Actually, you are right it does work, great... or somewhat great ;-). Because if I use other earlier defined variables in that calculation it does not work. Hmmm...strange... those earlier variables also runs smoothly btw... This is sooo strange.
Chansen is offline
Reply With Quote
View Public Profile
 
Old 01-20-2010, 12:10 PM Re: Javascript, isolated calculation
Experienced Talker

Posts: 42
Name: Chansen
Trades: 0
Anywho,.. It is great to finally know FOR SURE, that variable can contain ( ), a info piece I got from a website "first chapter javascript"-something-bs (may I kill this person, just a little bit?)
Chansen is offline
Reply With Quote
View Public Profile
 
Old 01-20-2010, 12:17 PM Re: Javascript, isolated calculation
Experienced Talker

Posts: 42
Name: Chansen
Trades: 0
Oh btw, if I use the earlier defined variables in this calculation I get the sum -6358.166666666667 - maybe this could lead to some extravagance knowledge of yours, Chris ?!? :-)
Chansen is offline
Reply With Quote
View Public Profile
 
Old 01-20-2010, 01:39 PM Re: Javascript, isolated calculation
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Don't you have learned the rules of operator precedence in mathematics ?

The division and multiplication operator have precedence over addition and subtraction.

So, even if javascript would not support the ( and ) in a computation,
Code:
140625-(530*12)
is equivalent to
Code:
140625-530*12
and to prove it:
Code:
Python 2.6 (r26:66721, Oct  2 2008, 11:35:03)
Type "help", "copyright", "credits" or "license" for more information.
>>> print 140625-(530*12)
134265
>>> print 140625-530*12
134265
>>>
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-20-2010, 06:28 PM Re: Javascript, isolated calculation
Experienced Talker

Posts: 42
Name: Chansen
Trades: 0
Tripy, were you born yesteryear?
Chansen is offline
Reply With Quote
View Public Profile
 
Old 01-20-2010, 07:13 PM Re: Javascript, isolated calculation
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I'm not sure I translate that word correctly, but if it's the case then yep, I might be almost as old as your parent, so be warned...
:-]
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-20-2010, 07:15 PM Re: Javascript, isolated calculation
Experienced Talker

Posts: 42
Name: Chansen
Trades: 0
Did you at all read my post? Guess not.
Chansen is offline
Reply With Quote
View Public Profile
 
Old 01-20-2010, 07:21 PM Re: Javascript, isolated calculation
Experienced Talker

Posts: 42
Name: Chansen
Trades: 0
This is really getting boring.... a moderator getting in the motor for absolutely no reason... zzz... I will now consider embarking... Too weird
Chansen is offline
Reply With Quote
View Public Profile
 
Old 01-20-2010, 07:23 PM Re: Javascript, isolated calculation
Experienced Talker

Posts: 42
Name: Chansen
Trades: 0
My life is too shor. Thank you to Chris and Jeremy for answers to my questions... I am definitely off. Give Tripy a hug, this person surely needs it. Have fun yall!
Chansen is offline
Reply With Quote
View Public Profile
 
Old 01-21-2010, 11:13 AM Re: Javascript, isolated calculation
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by tripy View Post
I'm not sure I translate that word correctly, but if it's the case then yep, I might be almost as old as your parent, so be warned...
:-]
And I could be older than your parents
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Javascript, isolated calculation
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.81245 seconds with 12 queries