function objectResult(){ var students = []; //학생 정보 배열을 만든다. students.push({ 이름:'홍길동', 국어:87, 수학:98, 영어:88, 과학:95 }); students.push({ 이름:'이산이', 국어:92, 수학:98, 영어:96, 과학:98 }); students.push({ 이름:'정도준', 국어:76, 수학:96, 영어:94, 과학:90 }); students.push({ 이름:'이순신', 국어:98, 수학:92, 영어:96, 과학:92 }); students.push({ 이름:'김유신', 국어:95, 수학:98, 영어:98, 과학:98 }); students.push({ 이름:'장보고', 국어:64, 수학:88, 영어:92, 과학:92 }); students.push({ 이름:'문익점', 국어:82, 수학:86, 영어:98, 과학:88 }); students.push({ 이름:'장영실', 국어:88, 수학:74, 영어:78, 과학:92 }); students.push({ 이름:'철수', 국어:97, 수학:92, 영어:88, 과학:95 }); students.push({ 이름:'영희', 국어:45, 수학:52, 영어:72, 과학:78 }); //모든 students 배열내의 객체에 메서드를 추가한다. for(var i in students){ //총점 구하는 메서드를 추가한다. students[i].getSum = function(){ return this.국어 + this.수학 + this.영어 + this.과학; }; //평균을 구하는 메서드를 추가한다. students[i].getAverage = function(){ return this.getSum() / 4; }; } //출력 var output = '이름\t총점\t평균\n'; for (var i in students){ with (students[i]){ output += 이름 + ' \t' + getSum() + '\t' + getAverage()+ '\n'; } } alert(output ); }