Skip to content

js-HW #33

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 2 commits 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
19 changes: 19 additions & 0 deletions 2017-hellojs_overflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//賴彥嘉
//getBMI
function getBMI(height, weight){
return weight/(height*height);
}
console.log(getBMI(1.88, 74));
// getMessage
var message ;
Copy link

Choose a reason for hiding this comment

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

如果已經有用return就可以不用再透過message存訊息了。

function getMessage(height, weight){
return weight/(height*height);
Copy link

Choose a reason for hiding this comment

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

如果是寫這樣的話,getMessage函式不就跟getBMI功能一樣了?

}
var bmi= getMessage(1.7,74)
Copy link

@Evafly Evafly Aug 4, 2017

Choose a reason for hiding this comment

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

直接bmi=getBMI(height,weight);取得BMI值就好,

if(bmi<18.5){
message = '過輕';}
else if(bmi>24){
message='過重' }
else{
message='正常'}
Copy link

Choose a reason for hiding this comment

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

13~18行應該放到getMessage函式中判斷,每個判斷都要return一個訊息,例如:

if(bmi<18.5){
    return "過輕";
}

console.log(message); //
Copy link

@Evafly Evafly Aug 4, 2017

Choose a reason for hiding this comment

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

console.log(getMessage(1.7,74));印出函式結果就可以了

19 changes: 19 additions & 0 deletions 2017.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//賴彥嘉
//getBMI
function getBMI(height, weight){
return weight/(height*height);
}
console.log(getBMI(1.88, 74));
// getMessage
var message ;
function getMessage(height, weight){
return weight/(height*height);
}
var bmi= getMessage(1.7,74)
if(bmi<18.5){
message = '過輕';}
else if(bmi>24){
message='過重' }
else{
message='正常'}
console.log(message); //