<!DOCTYPE html>
<html lang="ko">
<head>
<meta name="viewport" content="width=device-width">
<meta charset="UTF-8">
<link rel="stylesheet" href="https://meyerweb.com/eric/tools/css/reset/reset.css">
<title>Object</title>
</head>
<body>
<script>
var rect = {
width: 13,
height: 8,
getArea: function () {
return this.width * this.height;
}
};
console.groupCollapsed('Ex-01');
console.log('Width of rect: ' + rect.width);
console.log('Height of rect: ' + rect.height);
console.log('Area of rect: ' + rect.getArea());
console.groupEnd();
</script>
<script>
var student = {
name: '김철수',
korean: 92,
math: 76,
english: 84,
average: 0,
grade: 'F',
getAverage: function() {
this.average = (this.korean + this.math + this.english) / 3;
return this.average;
},
getGrade: function () {
this.getAverage();
if (this.average > 90) this.grade = 'A';
else if (this.average >= 80) this.grade = 'B';
else if (this.average >= 70) this.grade = 'C';
else if (this.average >= 60) this.grade = 'D';
else this.grade = 'F';
return this.grade;
},
printConsole: function () {
this.getGrade();
console.log('Name = ' + this.name);
console.log('Average = ' + this.average);
console.log('Grade = ' + this.grade);
}
};
console.groupCollapsed('Ex-02');
student.printConsole();
console.groupEnd();
</script>
</body>
</html>
