Back to feed
Renewal·서른의 생활코딩

Sample Source 2) JavaScript Basics (Exercise 1)

NS
normalstory
cover image



문제 1 : 1~25까지의 연속된 숫자로 되어있는 5*5 테이블 만들기
 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">




<head>


<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />


<title> 문제 1 </title>


</head>




<body>


<script type="text/javascript">


//<!CDATA[




/* 




for(i=1;i<=25;i++){




if(i%5==1){


document.write("<br />");


}


document.write("<td>" + i + "</td>");


}




/// -> 


document.write("<table border=1>");




for(i=1;i<=25;i++){




if(i%5==1){


document.write("<tr>");


}




document.write("<td>" + i + "</td>");




if(i%5==0){


document.write("</tr>");


}


}




document.write("</table>");




// 티쳐 : 의미 없는 tr이 반복되어 생성되늰 단점이있다.


*/


str1 = "<table border='1' width='150px' height='150px'>";


str1 += "<tr>";




//alert(str1);




for(i=1;i<=25;i++){


str1 += "<td>" + i + "</td>";


if(i%5==0){


str1 += "<tr>";


str1 +="</tr>";


}


}


str1 +="</table>";


document.write(str1);








//]]]]>


</script>




<br />


<table>


<tr>


<td>1</td><td>3</td><td>5</td>


</tr>


<tr>


<td>1</td><td>3</td><td>5</td>


</tr>


</table>






</body>


</html>

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.

More on the author's page

Keep reading

Renewal

Why You Should Use .html Instead of .md Seeing Is Believing

Jul 25, 2026·1 min
Renewal

The Most Important Thing About AX

Jul 17, 2026·2 min
Renewal

디지털 기술과 혁신에 대한 논고(지탱하는 힘)

Jul 17, 2026·5 min