2015-10-06 68 views
1

我有一個基本的問題,我認爲,它涉及到jscalc.io在https://jscalc.io/找到。語法jscalc.io,基本計算器

用下面的代碼我試圖得到一個基於輸出'required_volume'的表的三列輸出,但我似乎無法通過計算的值。

required_volume與roof_area * local_council相等,它正確顯示輸出,但是如何在表格的輸出中使用該結果?

我沒有得到任何錯誤,但也沒有輸出,誰能告訴我如何正確定義'required_volume'?

'use strict'; 

return { 

    required_volume: inputs.roof_area * inputs.local_council, 
    tanks_req: [{ 
     '100_percent': 'required_volume'/0.14, 
     '75_percent': 'required_volume'/(0.14/4 * 3), 
     '50_percent': 'required_volume'/(0.14/2) 
    }] 
} 

道歉,如果這是沒有意義的,或者我做錯了什麼,一小撮恐怕。

謝謝。

回答

1

jscalc.io,希望您在函數內編寫代碼並返回您在output部分中定義的屬性。

的功能是這樣的:

function(inputs) { 
    [Your script goes here] 
} -> outputs 

你在做什麼,而不是在於你寫你的邏輯來計算return塊內的中間值(volume)。你應該做的,而不是是這樣的:

'use strict'; 
var vol = inputs.area * inputs.council; /* intermediate calc here */ 
return { 
    volume: vol, 
    tanks: [{ 
     'percent-100': vol/0.14, 
     'percent-75': vol/(0.14/4 * 3), 
     'percent-50': vol/(0.14/2) 
    }] 
}; 

areacouncil是你定義的輸入,volume是你定義輸出tanks是你定義輸出percent-100等爲

這裏是你的calc:https://jscalc.io/calc/xhQCndfXmBuLpJPS

+0

感謝您的幫助,我真的很感激它。 – JPB