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