各位,獻醜了,可以忽略我這篇xd
這是一個很簡單的練習,計算BMI值
建立一個countBMI.js的檔案,再建立一個getBMI.js的檔案去require countBMI這個檔案。
在countBMI做exports的動作,然後在getBMI做require,執行後log出結果。
檔名 : countBMI.js
檔名 : getBMI.js
這是一個很簡單的練習,計算BMI值
建立一個countBMI.js的檔案,再建立一個getBMI.js的檔案去require countBMI這個檔案。
在countBMI做exports的動作,然後在getBMI做require,執行後log出結果。
檔名 : countBMI.js
//this is an module to help you count your BMI
var yourname,
h=0,
w=0,
result;
exports.setName = function(username, userh, userw){
yourname = username;
h = userh;
w = userw;
};
exports.countBMI = function(){
result = Math.floor(w/(h*h));
console.log("Hello "+yourname+"! \nYour BMI is "+result);
};
檔名 : getBMI.js
var myBMI = require('./countBMI');
myBMI.setName('WinWu',1.55, 50);
myBMI.countBMI();
沒有留言:
張貼留言
若你看的文章,時間太久遠的問題就別問了,因為我應該也忘了... XD