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

BMI 計算機 #15

wants to merge 1 commit into from

Conversation

battle0450
Copy link

No description provided.


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);了,這樣就有使用到傳入的參數了

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.

這行不需要

{
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結果

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));


}
getBMI(65,171);
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函式傳入的參數

}
getBMI(65,171);
var BMI = getBMI(65,171);
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.

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

{
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 "要顯示的結果"就可以了

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));就好囉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants