테이블 출력하기
1.1 for문을 이용해서 테이블을 출력하시오!
{
let table = "<table>";
for (let i = 1; i <= 5; i++) {
table += "<tr>";
for (let j = 1; j <= 5; j++) {
table += "<td>1</td>";
}
table += "</tr>";
}
table += "</table>";
}
1 | 1 | 1 | 1 | 1 |
1 | 1 | 1 | 1 | 1 |
1 | 1 | 1 | 1 | 1 |
1 | 1 | 1 | 1 | 1 |
1 | 1 | 1 | 1 | 1 |
1.2 for문을 이용해서 테이블을 출력하시오!
1~25까지 숫자를 넣으시오!
{
let num = 1;
let table = "<table>";
for( let i=1; i<=5; i++){
table +="<tr>";
for(let j=1; j<=5; j++){
table +="<td>" + num + "</td>";
num++;
}
table +="</tr>";
}
table +="</table>";
}
1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 |