vForums Support > Programming & Coding :: Code Requests & Support :: > Mini-Profile code (modification)

Mini-Profile code (modification) - Posted By Aiken (ionfortuna) on 16th Jan 10 at 5:15am
Was (worked):
Code:
 
  1. <script type="text/javascript">
  2.  
  3. function Token(Tokens){
  4.  
  5. var Tokens = parseInt(Tokens.replace(/[^0-9]/gi, ''));
  6.  
  7. var TokenPost = '';
  8. var TokenMod = 0;
  9.  
  10. if(Tokens >= 10000){
  11.  
  12. TokenMod = parseInt(Tokens/10000);
  13.  
  14. TokenPost += '<img src="http://i266.photobucket.com/albums/ii280/Ryuzaki_Master/TFAH_Token_Platinum.gif"> ' + TokenMod + ' Platinum Token';
  15.  
  16. if(TokenMod != 1){
  17. TokenPost += 's';
  18. }
  19.  
  20. } else if(Tokens >= 500){
  21.  
  22. TokenMod = parseInt(Tokens/500);
  23.  
  24. TokenPost = '<img src="http://i266.photobucket.com/albums/ii280/Ryuzaki_Master/TFAH_Token_Gold.gif"> ' + TokenMod + ' Gold Token';
  25.  
  26. if(TokenMod != 1){
  27. TokenPost += 's';
  28. }
  29.  
  30. TokenPost += '<br>';
  31.  
  32. } else if(Tokens >= 20){
  33.  
  34. TokenMod = parseInt(Tokens/20);
  35.  
  36. TokenPost = '<img src="http://i266.photobucket.com/albums/ii280/Ryuzaki_Master/TFAH_Token_Silver.gif"> ' + TokenMod + ' Silver Token';
  37.  
  38. if(TokenMod != 1){
  39. TokenPost += 's';
  40. }
  41.  
  42. } else {
  43.  
  44. TokenMod = Tokens
  45.  
  46. TokenPost = '<img src="http://i266.photobucket.com/albums/ii280/Ryuzaki_Master/TFAH_Token.gif"> ' +  TokenMod + ' Copper Token';
  47.  
  48. if(TokenMod != 1){
  49. TokenPost += 's';
  50. }
  51.  
  52. }
  53.  
  54. return TokenPost;
  55.  
  56. }
  57.  
  58. </script>
 


Now (doesn't work):
Code:
 
  1. <script type="text/javascript">
  2.  
  3. function Token(Tokens){
  4.  
  5. var Tokens = parseInt(Tokens.replace(/[^0-9]/gi, ''));
  6.  
  7. var TokenPost = '';
  8. var TokenMod = 0;
  9. var TokenMod20 = 0;
  10. var TokenMod500 = 0;
  11. var TokenMod2500 = 0;
  12.  
  13. while(Tokens >= 2500){
  14. Tokens -= 2500;
  15. ++TokenMod2500
  16. }
  17.  
  18. TokenPost += '<img src="http://i266.photobucket.com/albums/ii280/Ryuzaki_Master/TFAH_Token_Platinum.gif"> ' + TokenMod2500 + ' Platinum Token';
  19.  
  20. if(TokenMod2500 != 1){
  21. TokenPost += 's';
  22. }
  23.  
  24. while(Tokens >= 500){
  25. Tokens -= 500;
  26. ++TokenMod500
  27. }
  28.  
  29. TokenPost += '<br><img src="http://i266.photobucket.com/albums/ii280/Ryuzaki_Master/TFAH_Token_Gold.gif"> ' + TokenMod500 + ' Gold Token';
  30.  
  31. if(TokenMod500 != 1){
  32. TokenPost += 's';
  33. }
  34.  
  35. while(Tokens >= 20){
  36. Tokens -= 20;
  37. ++TokenMod20
  38. }
  39.  
  40. TokenPost += '<br><img src="http://i266.photobucket.com/albums/ii280/Ryuzaki_Master/TFAH_Token_Silver.gif"> ' + TokenMod20 + ' Silver Token';
  41.  
  42. if(TokenMod20 != 1){
  43. TokenPost += 's';
  44. }
  45.  
  46. TokenMod = Tokens;
  47.  
  48. TokenPost += '<br><img src="http://i266.photobucket.com/albums/ii280/Ryuzaki_Master/TFAH_Token.gif"> ' +  TokenMod + ' Copper Token';
  49.  
  50. if(TokenMod != 1){
  51. TokenPost += 's';
  52. }
  53.  
  54. return TokenPost;
  55.  
  56. }
  57.  
  58. </script>
 


The new version won't display anything

Displays the currency Tokens as Copper Tokens, Silver Tokens, Gold Tokens, and Platinum Tokens

Working version just shows the amount of the highest available type
New version supposed to show all types and their amount
I want to only show types of the highest available type and below

Re: Mini-Profile code (modification) - Posted By Michael (wrighty) on 16th Jan 10 at 11:48pm
<script type="text/javascript">
function Token(Tokens){
     var numbers = [
          ["http://i266.photobucket.com/albums/ii280/Ryuzaki_Master/"], //Root Image Directory
          ["Platinum", "2500", "TFAH_Token_Platinum.gif"],
          ["Gold", "500", "TFAH_Token_Gold.gif"],
          ["Silver", "20", "TFAH_Token_Silver.gif"],
          ["Copper", "1", "TFAH_Token.gif"]
     ];
     var out = '';
     for(i = 1; i < numbers.length; i++){
          var temp = 0;
          while(Tokens >= numbers[i][1]){
               Tokens -= numbers[i][1];
               temp++;
          }
          out += '<img src = "' + numbers[0] + numbers[i][2] + '" />' + temp + ' ' + numbers[i][0] + ' Token' + (temp != 1? 's' : '') + '<br />';
     }
     return out;
}

document.write(Token(3021));
document.write('<br />' + Token(1234));
</script>


{Smile}

Try that. I've included the
document.write
at the bottom for you.

Re: Mini-Profile code (modification) - Posted By Aiken (ionfortuna) on 17th Jan 10 at 12:18am
After a small modification to your code it worked, you forgot to add:

Code:
 
  1. var Tokens = parseInt(Tokens.replace(/[^0-9]/gi, ''));
 


at the top of the function

Re: Mini-Profile code (modification) - Posted By Michael (wrighty) on 17th Jan 10 at 12:20am
That isn't needed! {Wink}

Re: Mini-Profile code (modification) - Posted By Aiken (ionfortuna) on 17th Jan 10 at 1:03am
Actually, it is needed for me.
With out it on my profile 55 Tokens displayed as 1 Platinum Token but now it is 2 Silver Tokens and 15 Copper Tokens

Re: Mini-Profile code (modification) - Posted By Michael (wrighty) on 17th Jan 10 at 1:08am
Ok {Smile}