라라리라

2023.09.11 / Step 4 [DOM_태그생성] - 코딩 49 일차 본문

코딩/2023 JavaScript DOM

2023.09.11 / Step 4 [DOM_태그생성] - 코딩 49 일차

헤실 2023. 9. 11. 17:40

_0407_문자열로테이블생성1.html

 

<!DOCTYPE html>
<html lang="ko">
<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>
        let str = "<table border='1'>";
        str += "<tr>";
        str += "<td>1</td><td>2</td><td>3</td>";
        str += "</tr>";
        str += "<tr>";
        str += "<td>1</td><td>2</td><td>3</td>";
        str += "</tr>";
        str += "<tr>";
        str += "<td>1</td><td>2</td><td>3</td>";
        str += "</tr>";
        str += "</table>";
        document.write(str);
    </script>
</body>
</html>

 

Document

 


_0408_문자열로테이블생성2.html

 

<!DOCTYPE html>
<html lang="ko">
<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>
        document.write("<h1>구구단표</h1>");
        document.write("<table border='2'>");
   
        for (let i = 1; i <= 9; i++) {  
            document.write("<tr>");
            document.write("<td>" + i + "</td>");
   
            for (let j = 2; j <= 9; j++) {
                document.write("<td>" + i * j + "</td>");
            }
   
            document.write("</tr>");
        }
   
        document.write("</table>");
    </script>
</body>
</html>

 

Document

 


_0409_문자열로스타일생성1.html

 

<!DOCTYPE html>
<html lang="ko">
<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>
    <style>
        .blue { color: #00f; }
        .red { color: #f00; }
    </style>
</head>
<body>
    <script>
        let i = 20;
        while( i >= 10 ){
            if( i % 2 == 0 ){
                document.write("<p class='blue'>" + i + "</p>");
            }else{
                document.write("<p class='red'>" + i + "</p>");
            }
            i--;
        }
    </script>    
</body>
</html>

 

Document

 


_0410_문자열로스타일생성2.html

 

<!DOCTYPE html>
<html lang="ko">
<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>
    <style>
        .red{color: #f00;}
        .green{color: #00f;}
        .aqua{color: #0ff;}
    </style>
</head>
<body>
    <script>
        for(let i = 1; i <= 100; i++){
            if(i % 5 == 0 && i % 7 != 0) {
                document.write("<p class='red'>"+i+"</p>");
            } else if(i % 7 == 0 && i % 5 != 0) {
                document.write("<p class='green'>"+i+"</p>");
            } else if(i % 7 == 0 && i % 5 == 0) {
                document.write("<p class='aqua'>"+i+"</p>");
            }
        }
    </script>
</body>
</html>

 

Document