Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter07 : 객체문제 본문

WEB.JS/06.객체_JS

chapter07 : 객체문제

GAWON 2023. 5. 22. 09:15
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
/*
1.빈 객체 car생성
2.객체 car 동적으로 프로퍼티 추가
1)model = 아무거나
2)speed = 0
3)oil = 50;
4)max_SPEED= 100
5)speedUp 함수 -> speed 10증가시 oil 5 사용
5)speedDown 함수 -> speed 감소에 oil 미사용

```
 */
var car = {};

var car = {
	model : "e-class",
	speed : 0,
	oil : 50,
	max_SPEED : 100,

	speedUp : function() {
		//speed 10증가시 oil 5 사용
		if (this.oil >= 5) {
			this.speed += 10;
			this.oil -= 5;
			if (this.speed > this.max_SPEED) {
				this.speed = this.max_SPEED
			}
		}
	},
	speedDown : function() {
		//speed 감소에 oil 미사용
		this.speed -= 10;
		if (this.speed < 0) {
			this.speed = 0;
		}
	}
};

document.write("<h1>현재 속도" + car.speed + "잔여 기름량" + car.oil + "</h1>");
car.speedUp();
document.write("<h1>현재 속도" + car.speed + "잔여 기름량" + car.oil + "</h1>");
car.speedDown();
document.write("<h1>현재 속도" + car.speed + "잔여 기름량" + car.oil + "</h1>");
car.speedDown();
document.write("<h1>현재 속도" + car.speed + "잔여 기름량" + car.oil + "</h1>");

document.wirte(car);
document.write("<h1>" + car.speedDown() + "</h1>");
document.write("<h1>" + car.max_SPEED + "</h1>");

```

</script>
</head>
<body>

</body>
</html>

'WEB.JS > 06.객체_JS' 카테고리의 다른 글

chapter06 : 생성자함수  (0) 2023.05.19
chapter05 : 객체  (0) 2023.05.19
chapter04 : 객체  (0) 2023.05.19
chapter03 : 객체  (0) 2023.05.19
chapter02 : 객체  (0) 2023.05.19