Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JS adding two variabes help!

    I was just looking at this and wondered how you would go about this.

    Here's my code -

    Code:
    	str += text[8][lang]+"\n "+formatNumber(ganimet[0], color[22], color[21],5000000)+" "+
    	text[13][lang]+", "+formatNumber(ganimet[1], color[22], color[21],5000000)+
    	" "+text[14][lang]+" "+text[21][lang]+" "+formatNumber(ganimet[2], color[22], color[21],5000000)+
    	" "+text[15][lang]+
    which generates the below -

    Code:
    He captured
    11.219 metal, 7.363 crystal and 4.462 deuterium.
    text[13],[14] and [15] being the crystal metal and deut text's,

    so that means I want to add together the following variables that are highlighted below -

    Code:
    +formatNumber(ganimet[0], color[22], color[21],5000000)+
    +formatNumber(ganimet[1], color[22], color[21],5000000)+
    +formatNumber(ganimet[2], color[22], color[21],5000000)+
    how would I add all of the above variables to create a new line that says -

    Code:
    Total Profit: 23.044
    Any ideas?

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Try this modificaton:
    Code:
    str += text[8][lang]+"\n "+formatNumber(ganimet[0], color[22], color[21],5000000)+" "+
    	text[13][lang]+", "+formatNumber(ganimet[1], color[22], color[21],5000000)+
    	" "+text[14][lang]+" "+text[21][lang]+" "+formatNumber(ganimet[2], color[22], color[21],5000000)+
    	" "+text[15][lang]+'\nTotal Profit: '+((formatNumber(ganimet[0], color[22], color[21],5000000))+(formatNumber(ganimet[1], color[22], color[21],5000000))+(formatNumber(ganimet[2], color[22], color[21],5000000))
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •