Skip to content

安安我是天澤 #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
2. 完成後將你的資料 PR 回這個 repo。
3. 檔名命名為 `{年度}-{組別名稱}-{slackId}`
4. 例如:`2017-dateline-xxxx`

## Start the program
Clone and enter the project then execute:
`npm start`
32 changes: 32 additions & 0 deletions bmi-calculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var readline = require('readline');

var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

rl.question('Enter your height: ', function (height) {
rl.question('Enter your weight: ', function (weight) {
console.log("Your BMI=",getBMI(height, weight));
console.log(getMessage(height, weight));
rl.close();
});
});

function getBMI(height, weight) {
var bmi = weight/Math.pow(height/100, 2);
return bmi;
}

function getMessage(height, weight) {
var bmi = weight/Math.pow(height/100, 2);
if(bmi >= 24 ){
return "Your weight is too heavy.";
}
else if(bmi >= 18.5 && bmi < 24){
return "Your weight is normal.";
}
else if(bmi < 18.5){
return "Your weight is too light.";
}
}
216 changes: 216 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "ex1",
"version": "1.0.0",
"description": "My first npm practice.",
"main": "index.js",
"scripts": {
"start": "node bmi-calculator.js",
"test": "echo \"Error: no test specified\" && exit 1",
"demo": "node bmi-calculator.js"
},
"author": "Qi-Ze Huang",
"license": "ISC",
"devDependencies": {
"mocha": "^3.4.2"
},
"dependencies": {
"jquery": "^3.2.1"
}
}