13-4. JS ํ•จ์ˆ˜ ์—ฐ์Šต๋ฌธ์ œ

2021. 10. 19. 15:49ใ†HTML + CSS + JS

728x90

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

์ฝ˜์†”๋กœ ๊ฒฐ๊ณผ ์ถœ๋ ฅ

๋‘ ์ˆ˜ ์ž…๋ ฅ ๋ฐ›์•„์„œ ๊ฐ™์œผ๋ฉด ๊ณฑํ•˜๊ณ , ๋‹ค๋ฅด๋ฉด ๋”ํ•˜๊ธฐ 

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

		function sumMulti(x,y) {
			if(x === y) {
				return x * y;
			}else {
				return x + y;
			}
		}
		console.log(sumMulti(5,10));
		console.log(sumMulti(10,10));
  </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>
</head>
<body>
	<script>
		var num1 = prompt("๋น„๊ตํ•  ์ฒซ๋ฒˆ์งธ ์ˆซ์ž");
		var num2 = prompt("๋น„๊ตํ•  ๋‘๋ฒˆ์งธ ์ˆซ์ž");

		function compareNum(x,y) {
			if(num1 === num2) {
				alert("๊ฐ™์Šต๋‹ˆ๋‹ค.");
			}else{
				if(num1 > num2) {
					alert(num1 + "(์ด)๊ฐ€ " + num2 +"๋ณด๋‹ค ํฝ๋‹ˆ๋‹ค.");
				}else {
					alert(num2 + "(์ด)๊ฐ€ " + num1 +"๋ณด๋‹ค ํฝ๋‹ˆ๋‹ค.");
				}
			}
		}

		compareNum(num1, num2);
	</script>

	
</body>
</html>
728x90