-
Notifications
You must be signed in to change notification settings - Fork 29
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
2017-緣-casper_cheng #31
base: master
Are you sure you want to change the base?
Conversation
2017-緣-casper_cheng.md
Outdated
|
||
console.log("weight:"+weight); | ||
|
||
console.log("BMI:"+weight/((height/100)*(height/100))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
作業要求是要使用函式回傳,這樣是直接輸出結果,並沒有回傳
所以建議寫法:
var bmi="BMI:"+weight/((height/100)*(height/100));
//宣告一個變數,將計算結果傳入參數
如果想要斷行顯示身高體重以及BMI,可以先宣告一個變數裝進去並使用/n
斷行再回傳
var str="height:"+height+"/nweight"+weight+"/nBMI:"+bmi;
return str;
2017-緣-casper_cheng.md
Outdated
|
||
|
||
|
||
getBMI(172,64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這邊再用console.log(getBMI(172,64));
印出結果
2017-緣-casper_cheng.md
Outdated
console.log("height:"+height); | ||
|
||
|
||
console.log("weight:"+weight); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這邊也是一樣,可以參考上面的寫法歐
2017-緣-casper_cheng.md
Outdated
if (bmi > 18 && bmi <25){console.log("good"); | ||
} | ||
|
||
if (bmi > 10 && bmi <18){ console.log("slim"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這邊的console.log();
也直接改成return "顯示訊息"
就可以了
2017-緣-casper_cheng.md
Outdated
|
||
|
||
|
||
getMessage(172,80); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
參考上面getBMI印出的寫法
下次還是上傳JS檔比較好歐^^ |
2017-緣-casper_cheng.md
Outdated
function getMessage(height,weight) | ||
{ | ||
|
||
var bmi = weight/((height/100)*(height/100)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這裡可以直接用 var bmi=getBMI(height,weight);
就好囉
function getBMI(height,weight){
console.log("height:"+height);
console.log("weight:"+weight);
console.log("BMI:"+weight/((height/100)*(height/100)));
}
getBMI(172,64);
function getMessage(height,weight)
{
var bmi = weight/((height/100)*(height/100));
console.log("height:"+height);
console.log("weight:"+weight);
if (bmi > 25){console.log("fat"); }
if (bmi > 18 && bmi <25){console.log("good"); }
if (bmi > 10 && bmi <18){ console.log("slim"); }
}
getMessage(172,80);