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

chapter07 : continue 본문

WEB.JS/02.제어문_JS

chapter07 : continue

GAWON 2023. 5. 19. 09:22
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
/*
5개의 양수만 입력 받아서(prompt) 평균 구하기
0이하의 숫자는 입력에서 제외하고 다시 입력.
숫자가 아닌 입력도 제외하고 다시 입력
-> isNaN(값) -> bool 리턴
*/

```
var cnt = 0;
var total = 0;
var num;
while(cnt < 5){
	num = Number(prompt("양수 입력"));

	if(num <= 0 || isNaN(num)){
		continue;
	}

	total += num;
	cnt++;
}

var avg = total / 5;
alert("평균 = " + avg);

```

</script>
</head>
<body>

</body>
</html>

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

chapter06 : for  (0) 2023.05.19
chapter05 : do_while  (0) 2023.05.19
chapter04 : while  (0) 2023.05.19
chapter03 : switch  (0) 2023.05.19
chapter02 : if  (0) 2023.05.19