3장_제어문.pdf

실습

if_1.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var walkAmount=prompt("당신의 하루 걷는 양은 몇 보인가요?","0");
        if(walkAmount >=10000){
            document.write("매우 좋은 습관을 지니고 계시는군요!!","<br>");
        }
        document.write("===== The End =====");
    </script>
</head>
<body>
    
</body>
</html>

20230406164548.png

if_1.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var userName=prompt("방문자의 이름은?","");

        //값이 있어야 참
        if(userName){
            document.write(userName+"님 반갑습니다");
        }
    </script>
</head>
<body>
    
</body>
</html>

20230406164901.png

else_1.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var num=prompt("당신이 좋아하는 숫자는?","0");
        
        if(num%2==0){
            document.write("당신이 좋아하는 숫자는 짝수입니다.");
        }else{
            document.write("당신이 좋아하는 숫자는 홀수입니다.");
        }
    </script>
</head>
<body>
    
</body>
</html>

20230406165120.png

else_2. html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var result = confirm("정말로 회원을 탈뢰하시겠습니까?");
        
        if(result){
            document.write("탈퇴 처리되었습니다!");
        }else{
            document.write("탈퇴 취소되었습니다!");
        }
    </script>
</head>
<body>
    
</body>
</html>

20230406165616.png

elseif_1.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var mon=prompt("현재는 몇 월입니까?","0");

        if(mon>=9 && mon<=11){
            document.write ("독서의 계절 가을이네요!");
        }else if(mon>=6 && mon<=8){
            document.write("여름!");
        }else if(mon<=5 && mon>=3){
            document.write("봄!");
        }else{
            document.write("겨울!");
        }
    </script>
</head>
<body>
    
</body>
</html>