JavaScript

자바스크립트 (JavaScript) - 18 : 실전 문제 모범 코드 (구구단 출력)

n.han 2016. 7. 18. 16:33

 

<!DOCTYPE html>

<html>

        <head>

        <style>

        table, th, td {

            border: 1px solid black;

            padding: 5px;

            border-collapse: collapse;

        }

        </style>

        <title></title>

        <meta charset="UTF-8">       

        <script>

               window.onload = function() {

                       var result = '<table>';

                       for(var i  = 0; i < 10 ; i++){

                              result += '<tr>';

                              for(var j = 2; j < 10; j++){

                                      result += '<th>';

                                      if(i == 0){

                                             result += j + '';

                                      } else {

                                             result += j + ' * ' + i + ' = ' + (j * i);

                                      }

                                      result += '</th>'

                              }

                              result += '</tr>';

                       }

                       result += '</table>';

                       document.body.innerHTML = result;

               };

        </script>

        </head>

<body>

</body>

</html>