on
객체생성자 함수
객체생성자 함수
Insert title here //객체 생성자 함수 function CheckWeight(name, height, weight){ this.userName = name; this.userHeight = height; this.userWeight = weight; this.minWeight; this.maxWeight; CheckWeight.prototype.getInfo = function(){ var str =""; str += "이름: " + this.userName+ ","; str += "키: " + this.userHeight+ ","; str += "몸무게: " + this.userWeight+ "
"; return str; } CheckWeight.prototype.getResult = function(){ this.minWeight = (this.userHeight - 100) * 0.9 - 5; this.maxWeight = (this.userHeight - 100) * 0.9 + 5; if(this.userHeight >= this.minWeight && this.userWeight <= this.maxWeight) { return "정상 몸무게입니다.
"; }else if(this.userWeight < this.minWeight){ return "저체중입니다.
"; }else return "과제중입니다.
"; } } var jang = new CheckWeight("장보리", 163, 53); var park = new CheckWeight("박달재", 180, 88); console.log(jang); console.log(park); document.write(jang.getInfo()); document.write(jang.getResult()); document.write(park.getInfo()); document.write(park.getResult());
공유하기 글 요소 저작자표시
from http://mezero.tistory.com/23 by ccl(A) rewrite - 2021-10-10 23:27:26