카테고리 없음

자바스크립트 - 간단한 실행문 작성

히연쓰 2021. 8. 2. 11:15

[1]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!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>
</head>
<body>
    <script>
        var age = prompt("당신의 나이는","0");
        if(age>=20) {
            document.write("당신은 성인입니다.");
        }
        else {
            document.write("당신은 미성년자 입니다.");
        }
    </script>
</body>
</html>l
cs

결과

promt 함수의 사용법 또한 알 수 있다.

 

[2]

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!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>
</head>
<body>
    <script>
        // border="n" 은 테이블의 테두리 결정
        var str = "<table border='3'>";
            str +="<tr>";
            str +="<td>1</td><td>2</td><td>3</td>";
            str +="</tr>";
            str +="</table>";
            document.write(str);
    </script>
</body>
</html>
cs

결과