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 Arithmetic Problem
Old 03-25-2008, 02:28 PM JavaScript Arithmetic Problem
tuestunim's Avatar
Experienced Talker

Posts: 41
Name: Scott Brown
Location: Huddersfield, UK
Trades: 0
Hi,

My JavaScript knowledge is very poor (I'm a layout artist(!!)) so could someone have a look at this for me and let me know what's going on.

http://www.lsi-gifts.co.uk/dev/jscalc/

The first two answer boxes work perfectly. However, I've been playing about with the third answer box and cannot get it to give the correct answer (which is 12.6 with the default values).

Can someone take a look at it for me and let me know what's going on. The formula I want to use is as follows:

(30f * (b+d) * (a + c)) / 1000

I'm not doing any of the others as the rest of the answers revolve around the same formula so sod that until I get this one right!

I look forward to your replies.

Cheers,

Scott.
tuestunim is offline
Reply With Quote
View Public Profile Visit tuestunim's homepage!
 
 
Register now for full access!
Old 03-26-2008, 05:16 PM Re: JavaScript Arithmetic Problem
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
It would probably be work out if you used the same equation in your javascript that you do in this post.
Code:
eval(
(calc.b.value + calc.d.value) * (calc.a.value + calc.c.value) * (30 * calc.f.value) / 1000
);
You're missing some parenthesis
Code:
eval(
( (calc.b.value + calc.d.value) * (calc.a.value + calc.c.value) * (30 * calc.f.value) )/ 1000
);
__________________

Please login or register to view this content. Registration is FREE


Last edited by willcode4beer; 03-26-2008 at 05:19 PM..
willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 03-27-2008, 01:40 PM Re: JavaScript Arithmetic Problem
tuestunim's Avatar
Experienced Talker

Posts: 41
Name: Scott Brown
Location: Huddersfield, UK
Trades: 0
Thanks for your help but it's still throwing out the same, wrong, answer I'm afraid. It's giving out 5949.9 rather than 12.6. I admit that it makes the product look very good but it's somewhat misleading!!

Any other ideas?

Cheers,

Scott.
tuestunim is offline
Reply With Quote
View Public Profile Visit tuestunim's homepage!
 
Old 03-27-2008, 10:21 PM Re: JavaScript Arithmetic Problem
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
doh!, I got hit with the oldest one in the book.
The string arithmetic was throwing it off (gotta convert those strings to numbers).
Try this:
Code:
eval(
  (
        (Number(calc.b.value) + Number(calc.d.value))
     * (Number(calc.a.value) + Number(calc.c.value))
     * (30 * Number(calc.f.value))
  )/ 1000
);
The new lines were just added for clarity
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 03-28-2008, 05:54 AM Re: JavaScript Arithmetic Problem
tuestunim's Avatar
Experienced Talker

Posts: 41
Name: Scott Brown
Location: Huddersfield, UK
Trades: 0
Thank you very much! All sorted now.
tuestunim is offline
Reply With Quote
View Public Profile Visit tuestunim's homepage!
 
Reply     « Reply to JavaScript Arithmetic Problem
 

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 1.80887 seconds with 12 queries