12-4. JS ์—ฐ์Šต๋ฌธ์ œ 1,2

2021. 10. 18. 19:06ใ†HTML + CSS + JS

728x90

* ์—ฐ์Šต๋ฌธ์ œ 1

๊ฒฐ๊ณผ 

HTML 

<!DOCTYPE html>
<html lang="ko">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>์—ฐ์Šต๋ฌธ์ œ 1</title>

	<style>
		body {
			text-align: center;
			font-size:1.2em;
		}
	</style>
</head>
<body>
	<h2>4์˜ ๋ฐฐ์ˆ˜์ผ๊นŒ ์•„๋‹๊นŒ</h2>

	<script>
		var num = prompt("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”");

		if(num !== null) {
			if(num % 4 === 0 ) {
				document.write(num + "๋Š” 4์˜ ๋ฐฐ์ˆ˜์ž…๋‹ˆ๋‹ค.");
			}
		}else {
			document.write("์ž…๋ ฅ ์ทจ์†Œ");
		}
	</script>
</body>
</html>

 

 

* ์—ฐ์Šต๋ฌธ์ œ 2

๊ฒฐ๊ณผ

<!DOCTYPE html>
<html lang="ko">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>์—ฐ์Šต๋ฌธ์ œ 2</title>
	<style>
		body {
			font-size:1.2em;
			text-align:center;
		}
		p {
			color: red;
			font-weight: bold;
		}
	</style>
</head>
<body>
	<h2>3์˜ ๋ฐฐ์ˆ˜ ์ฐพ๊ธฐ</h2>

	<script>
		var num = prompt("๋ช‡ ๊นŒ์ง€ 3์˜ ๋ฐฐ์ˆ˜๋ฅผ ์ฐพ์„๊นŒ์š”? ");
		var i;
		var count = 0; 


		if(num !== null) {
			for(i = 1; i<= num; i++) {
				if(i % 3 === 0) {
					count++;
					document.write(i + ", ");
				}
			}	
		}else {
			document.write("์ž…๋ ฅ์ทจ์†Œ");
		}

		document.write("<p> " + num + "๊นŒ์ง€ 3์˜ ๋ฐฐ์ˆ˜์˜ ๊ฐฏ์ˆ˜ : " + count);
	</script>
</body>
</html>
728x90