본문 바로가기

Programming/Javascript

계산과 alert()출력

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<script type="text/javascript">
		for (var i = 1; i <= 50; i++) {
			if (parseInt(i / 10) == 3
					&& (i % 10 == 3 || i % 10 == 6 || i % 10 == 9)) {
				document
						.write("<img src='./img/ggobugi.jfif' width=20 height=20>");
			} else if (parseInt(i / 10) == 3 || i % 10 == 3 || i % 10 == 6
					|| i % 10 == 9) {
				document
						.write("<img src='./img/pikachu.png' width=20 height=20>");
			} else {
				document.write(i);
			}
		}
	</script>
</body>
</html>

 

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<script type="text/javascript">
		let = array = [];
		array[0] = "사과";
		array[1] = "참외";
		array[2] = "파인애플";
		array[3] = "수박";
		array[4] = "딸기";
		
		for(let i=0; i<array.length; i++){
			console.log(array[i]);
		}
	</script>
</body>
</html>

 

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<script type="text/javascript">
		let array = [ 11, 12, 13, 14, 15 ];
		let odd = [];

		let j = 0;
		for (var i = 0; i < array.length; i++) {
			if (array[i] % 2 == 0) {
				odd[j++] = array[i];
			}
		}
		alert("arr에 들어있는 짝수는 " + odd + "이며, 총 " + odd.length + "개입니다.");
	</script>
</body>
</html>

 

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<script type="text/javascript">
		let arr = [ 24, 54, 78, 13, 44 ];
		let great = arr[0];

		for (var i = 0; i < arr.length; i++) {
			if (great < arr[i]) {
				great = arr[i];
			}
		}
		alert("최댓값 >> " + great);
	</script>
</body>
</html>

'Programming > Javascript' 카테고리의 다른 글

스크립트의 변수와 함수  (0) 2020.03.08
list의 push(), pop(), splice(, )  (0) 2020.03.08
confirm()과 prompt()의 계산출력  (0) 2020.03.08
script 출력  (0) 2020.03.08
addEventListener()와 document.querySelector()  (0) 2020.03.08