Skip to content

BMI 計算機 #15

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
21 changes: 21 additions & 0 deletions 2017-chu-battle0450/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//黃佳晨
var getBMI = function(weight, height){
return weight/((height/100)*(height/100));

}
getBMI(65,171);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這行不需要

var BMI = getBMI(65,171);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊先不要存入變數,因為這樣下面使用的BMI並沒有用到getMessage函式傳入的參數

console.log('BMI: '+BMI);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那這邊就先改成console.log('BMI:'+getBMI(65,171));


var getMessage = function(weight,height)
{
getBMI(weight,height);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這行也不需要

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊就可以宣告 var BMI=getBMI(weight,height);了,這樣就有使用到傳入的參數了

if(BMI<18.5)
console.log('體重過輕');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這樣是直接輸出,沒有做回傳的動作
作業題目是要函數回傳,所以先return訊息
再到函式外面log結果

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接return "要顯示的結果"就可以了

else if(BMI<24&&BMI>=18.5)
console.log('正常範圍');
else if(BMI>=24&&BMI<30)
console.log('過重');
}

getMessage(65,171);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

將函式中return的結果在這裡log出來
console.log(getMessage(65,171));

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這裡再console.log(getMessage(65,171));就好囉

13 changes: 13 additions & 0 deletions 2017-chu-battle0450/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "ex03",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node demo.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}