(cfconverter.js)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
'use strict'; const roundKeta2 = (n) => { n *= 100; n = Math.round(n); return n / 100.0; }; const c2F = (c) => roundKeta2(1.8 * c + 32); const f2C = (f) => roundKeta2((f - 32) / 1.8); exports.c2F = c2F; exports.f2C = f2C; |
(Main.js)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
'use strict'; const cfc = require('./cfconverter.js'); const dispC2F = (c) => { const f = cfc.c2F(c); console.log(c + ' ℃ : ' + f + ' ℉'); }; const dispF2C = (f) => { const c = cfc.f2C(f); console.log(f + ' ℉ : ' + c + ' ℃'); }; dispC2F(-273); dispF2C(cfc.c2F(-273)); dispC2F(0); dispF2C(cfc.c2F(0)); dispC2F(100); dispF2C(cfc.c2F(100)); |
1 2 3 4 5 6 |
-273 ℃ : -459.4 ℉ -459.4 ℉ : -273 ℃ 0 ℃ : 32 ℉ 32 ℉ : 0 ℃ 100 ℃ : 212 ℉ 212 ℉ : 100 ℃ |