Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

caspercheng
Copy link

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


console.log("weight:"+weight);

console.log("BMI:"+weight/((height/100)*(height/100)));
Copy link

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;




getBMI(172,64);
Copy link

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));印出結果

console.log("height:"+height);


console.log("weight:"+weight);
Copy link

Choose a reason for hiding this comment

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

這邊也是一樣,可以參考上面的寫法歐

if (bmi > 18 && bmi <25){console.log("good");
}

if (bmi > 10 && bmi <18){ console.log("slim");
Copy link

Choose a reason for hiding this comment

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

這邊的console.log();也直接改成return "顯示訊息"就可以了




getMessage(172,80);
Copy link

Choose a reason for hiding this comment

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

參考上面getBMI印出的寫法

@Evafly
Copy link

Evafly commented Aug 4, 2017

下次還是上傳JS檔比較好歐^^
然後記得在檔案上方寫上你的大名歐~

function getMessage(height,weight)
{

var bmi = weight/((height/100)*(height/100));
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(height,weight);就好囉

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.

2 participants