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

chapter11 : 함수문제 본문

WEB.JS/04.함수_JS

chapter11 : 함수문제

GAWON 2023. 5. 19. 17:34
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
/*
정수를 n 자리로 맞춰서 사용하기

```
  *num 값이 각각 1,2,3 일때

  ex) makeZeroNum (num,2) =>01 ,02 ,03...
  ex) makeZeroNum (num,3) =>001 ,002 ,003...
  ex) makeZeroNum (num,4) =>0001 ,0002 ,0003...

  함수 makeZeroNum 를 작성하시오

  * 문자열 길이 length 필드 사용
*/

var n = 0;
function makeZeroNum(num,n){
	num = String(num);
	while(true){
		num = "0" + num;
		if(num.length == n){
			break;
		}
	}
	   return num;
}

  document.write("<h3>" + makeZeroNum(1,2) + "</h3>"); // => 01
  document.write("<h3>" + makeZeroNum(1,3) + "</h3>"); // => 001
  document.write("<h3>" + makeZeroNum(1,4) + "</h3>"); // => 0001

```

</script>
</head>
<body>

</body>
</html>

'WEB.JS > 04.함수_JS' 카테고리의 다른 글

chapter13 : 함수문제  (0) 2023.05.19
chapter12 : 함수문제  (0) 2023.05.19
chapter10 : 타이머_내장함수  (0) 2023.05.19
chapter09 : 재귀함수  (0) 2023.05.19
chapter08 : 콜백함수  (0) 2023.05.19