<script type="text/javascript"> function BMI(height, weight, gender) { this.Height = Number(height)/100; //身長 this.Weight = Number(weight); //体重 this.Gender = gender; //性別 this.Bmi = parseInt(this.Weight / (this.Height * this.Height)); this.Disp = function() { var str= "身長:" + this.Height + " 体重:" + this.Weight + " BMI: " + this.Bmi + "<br>\n"; return str; } this.Msg = function() { var str= "18.5以上25.0未満が標準です。"; if (this.Gender==0) str= str + "男性の理想値は22.0です。 BMI: " + this.Bmi + "<br>\n"; else str= str + "女性の理想値は21.0です。 BMI: " + this.Bmi + "<br>\n"; return str; } } </script> </head> |
<script type="text/javascript"> var cls = new BMI(160, 64, 0); document.write(cls.Disp()); document.write(cls.Msg(), "<br>\n"); var cls = new BMI(155, 54, 1); document.write(cls.Disp()); document.write(cls.Msg()); </script><br> |
<script type="text/javascript"> function BMI(height, weight, gender) { this.Height = Number(height)/100; //身長 this.Weight = Number(weight); //体重 this.Gender = gender; //性別 this.Bmi = parseInt(this.Weight / (this.Height * this.Height)); |
this.Disp = function() { var str= "身長:" + this.Height + " 体重:" + this.Weight + " BMI: " + this.Bmi + "<br>\n"; return str; } |
this.Msg = function() { var str= "18.5以上25.0未満を標準です。"; if (this.Gender==0) str= str + "男性の理想値は22.0です。 BMI: " + this.Bmi + "<br>\n"; else str= str + "女性の理想値は21.0です。 BMI: " + this.Bmi + "<br>\n"; return str; } </script> |
<script type="text/javascript"> var cls = new BMI(160, 64, 0); document.write(cls.Disp()); document.write(cls.Msg(), "<br>\n"); var cls = new BMI(150, 54, 1); document.write(cls.Disp()); document.write(cls.Msg()); </script><br> |