Note that there are some explanatory texts on larger screens.

plurals
  1. PODictionary for missing value
    primarykey
    data
    text
    <p>Here is the code</p> <pre><code>converter = { 'SIToImperial' : { 'cm' : function(value) {return value * convertRatioImperial[0];}, 'm' : function(value) {return value * convertRatioImperial[1];}, 'km' : function(value) {return value * convertRatioImperial[2];}, 'g' : function(value) {return value * convertRatioImperial[3];}, 'kg' : function(value) {return value * convertRatioImperial[4];}, 't' : function(value) {return value * convertRatioImperial[5];}, 'mL' : function(value) {return value * convertRatioImperial[6];}, 'L' : function(value) {return value * convertRatioImperial[7];}, 'm3' : function(value) {return value * convertRatioImperial[8];}, 'kWh' : function(value) {return value;}, 'nb' : function(value) {return value;}, 'undefined': function(value) {return 'Not Found';} } } </code></pre> <p>It is clear that my line 'undefined'.... does not work like I want it to.</p> <p>I would like that when converter["SIToImperial"][units] is called with an 'units' not listed in the properties. Exemple : converter["SIToImperial"]['oz']. It should return the undefined line IE 'Not Found'.</p> <p>Could someone help me out I have tried various ways but I'm still not enough familiar with dictionnaries to get it working properly.</p> <p>Update :</p> <pre><code>//Generalized conversion function function convert(value,valueUnit,system, toSI) { var result; //From SI to Imp/U if(!toSI) { result = converter.guardian('SITo'+system,valueUnit,value); } else if(toSI)//To SI from Imp/US { result = converter.guardian(system+'ToSI',valueUnit,value); } return result; }; </code></pre> <p>and </p> <pre><code>converter = { guardian : function (system,units,value) {var label = this[system][units]; if(typeof(label) === 'undefined') {return "Not Found";} else {return label(value);}}, 'SIToImperial' : { 'cm' : function(value) {return value * convertRatioImperial[0];}, 'm' : function(value) {return value * convertRatioImperial[1];}, 'km' : function(value) {return value * convertRatioImperial[2];}, 'g' : function(value) {return value * convertRatioImperial[3];}, 'kg' : function(value) {return value * convertRatioImperial[4];}, 't' : function(value) {return value * convertRatioImperial[5];}, 'mL' : function(value) {return value * convertRatioImperial[6];}, 'L' : function(value) {return value * convertRatioImperial[7];}, 'm3' : function(value) {return value * convertRatioImperial[8];}, 'kWh' : function(value) {return value;}, 'nb' : function(value) {return value;} } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload