Notice
Recent Posts
Recent Comments
Link
«   2024/06   »
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
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter05 : do_while 본문

WEB.JS/02.제어문_JS

chapter05 : do_while

GAWON 2023. 5. 19. 09:21
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">

/*
적을 쓰러뜨려라!

1. 적은 100의 체력을 가지고있다
2. 한 번 공격 할 때마다 랜덤 0~29 사이의 체력을 닳게 할 수 있다
3.몇 번만에 적을 쓰러뜨렸는지 횟수를 출력하시오

ex)
1회 공격 결과 : 95 체력 남음!
2회 공격 결과 : 80 체력 남음!
...
5회 만에 적을 쓰러뜨렸다!

- /

```
 var enemy = 100;
 var attack;
 var cnt = 0;

 do{
	 rand = Math.floor(Math.random() * 30);
	 enemy -= attack;
	 enemy = enemy < 0 ? 0 : enemy;
	 cnt++;
	 document.write("<h3>" + cnt + "회 공격 결과 : " + enemy + "체력 남음!</h3>");
 }while(enemy > 0);

 document.write("<h3>" + cnt + "회 만에 적을 쓰러뜨려졌다!</h3>");

```

</script>
</head>
<body>

</body>
</html>

'WEB.JS > 02.제어문_JS' 카테고리의 다른 글

chapter07 : continue  (0) 2023.05.19
chapter06 : for  (0) 2023.05.19
chapter04 : while  (0) 2023.05.19
chapter03 : switch  (0) 2023.05.19
chapter02 : if  (0) 2023.05.19