View Single Post
Old 08-19-2012, 04:43 AM   PM User | #19
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,765
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
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.
jmrker is offline   Reply With Quote