Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Client Side Scripting
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 01-07-2005, 07:23 AM
  #1
Manguish
Aspirant (Level 2)
 
Join Date: Jan 2005
Posts: 12
iTrader: (0)
Manguish is on a distinguished road
More "efficient" javascript

Heres a funtion i wrote for a small calculation.

It looks messy, but i was unable to get it to work doing it with brackets etc...

PHP Code:
function computeAnalysis( ) {
var 
drivespk document.speedcalc.drive.value ;
var 
drivenspk document.speedcalc.axle.value ;
var 
revs document.speedcalc.rpm.value ;
var 
size document.speedcalc.tiremm.value ;
var 
calc1 = (revs drivespk) ;
var 
calc2 = (calc1 drivenspk) ;
var 
calc3 = (calc2 size) ;
var 
calc4 = (calc3 60) ;
var 
calc5 = (calc4 63360) ;

    
document.speedcalc.ratio.value = (drivenspk drivespk)
    
document.speedcalc.mph.value Math.round(calc5*10)/10
    
return true

It's mainly the calc variables i'm looking at. Can i shorten it into a nice tidy sum?
Manguish is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 01-07-2005, 07:42 AM
  #2
RysChwith
Super Guru
 
Join Date: Jun 2004
Posts: 4,191
iTrader: (0)
RysChwith will become famous soon enough
PHP Code:
function computeAnalysis( ) { 
var 
drivespk document.speedcalc.drive.value 
var 
drivenspk document.speedcalc.axle.value 
var 
revs document.speedcalc.rpm.value 
var 
size document.speedcalc.tiremm.value 

    
document.speedcalc.ratio.value = (drivenspk drivespk
    
document.speedcalc.mph.value Math.round( ( ( ( ( ( revs drivespk ) / drivenspk ) * size ) * 60 ) / 63360 10 ) / 10 
    
return true 

That ought to work. Of course, given that you're using only multiplication and division, you ought to be able to remove the parentheses entirely and trust the order of operations (left to right) to handle it. I like to keep the parens in, though, just for sanity's sake.

Rys
RysChwith is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 01-07-2005, 07:47 AM
  #3
Manguish
Aspirant (Level 2)
 
Join Date: Jan 2005
Posts: 12
iTrader: (0)
Manguish is on a distinguished road
Cheers - i did try that but it blommin never worked

I must have missed a parentheses or something.

Cheers for confirming i'm not daft or loosing my mind though
Manguish is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Reply
KEEP TABS
SPONSORS
 
Boxedart

 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 05:42 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.