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>