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.
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Regular Coder
    Join Date
    Aug 2012
    Posts
    112
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Hmm.. that works. Interesting.

    The problem is that part with the goofy logic is necessary so that it doesn't say things like "1 pounds". Is there anyway to keep it or alter it?

    by the way, the code you gave me is at /converter2.html
    Last edited by Ilan; 08-19-2012 at 02:39 AM.

  2. #17
    Regular Coder
    Join Date
    Aug 2012
    Posts
    112
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Besides formatting, could you show me the changes you made?

  3. #18
    Regular Coder
    Join Date
    Aug 2012
    Posts
    112
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Fixed.


    Quote Originally Posted by Old Pedant View Post
    Add it to any *string* that you want changed.

    Code:
    document.getElementById('result').value = quantity + " " + inunittext.toLowerCase() + "s of " + 
                substanceAsText + " = " + result + " " + outunittext + "s of " + substanceAsText.toLowerCase();
    Or convert the entire string all at once:
    Code:
    document.getElementById('result').value = 
       ( quantity + " " + inunittext + "s of " + substanceAsText 
         + " = " + result + " " + outunittext + "s of " + substanceAsText ).toLowerCase();
    Works perfectly

  4. #19
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,097
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    Quote Originally Posted by Ilan View Post
    Hmm.. that works. Interesting.

    The problem is that part with the goofy logic is necessary so that it doesn't say things like "1 pounds". Is there anyway to keep it or alter it?

    by the way, the code you gave me is at /converter2.html
    Study on this a bit...
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <meta charset="utf-8" />
    <title> Untitled </title>
    
    <style type="text/css">
    
    </style>
    </head>
    <body>
    <b>Results:</b><br>
    <input type="text" id="result" value="" size="60">
    
    <script type="text/javascript">
    
    // following for testing purposes only
      var quantity = 1;  // change quantity to 2 or some fraction
      var result = 2;    // change result to 1 or some fraction
      var inunittext = 'cup';
      var outunittext = 'gram';
      var substanceAsText = 'SUBSTANCE TEXT';
    
      var qplural = '';  var rplural = '';
      if (quantity != 1) { qplural = 's'; }
      if (result != 1) { rplural = 's'; }
    
    // Conversion calculations left out for testing purposes
      var str  = quantity + " " + inunittext + qplural + " of " + substanceAsText
               + " = " + result + " " + outunittext + rplural + " of " + substanceAsText;
      document.getElementById('result').value = str.toLowerCase();
    
    </script>
    </body>
    </html>
    Change the 'quantity' and/or 'result' settings to something other than '1'
    to see the effects of the plural logic.


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

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