prova questo codice

codice:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>xhtml 1.0</title>

		<style type="text/css">
		table {
			border-collapse	: collapse;
		}
		table, td {
			border				: 1px #ccd solid;
		}

		td {
			width				: 35px;
			text-align			: center;
		}
		</style>
	</head>

<body>

<script type="text/javascript">
// <![CDATA[

	function tavolaPitagorica(n, caption) {

		var table = '<table>';
		for (i=1; i<=n; i++) {
			table  += '<tr>';
			for (j=1; j<=n; j++) {
				table += '<td>'+ (i * j) +'</td>';
			}
			table  += '</tr>';
		}

		table += '</table>';
		if (caption) table += '

'+ caption +'</p>';
		document.write(table);
	}

	tavolaPitagorica(4, 'tavola pitagorica 4x4');

	tavolaPitagorica(8, 'tavola pitagorica 8x8');

	tavolaPitagorica(10, 'tavola pitagorica 10x10');

// ]]>
</script>

</body>
</html>
lascio a te le modifiche eventuali (stile, posizione del caption, ...) e l'analisi della soluzione
(innerhtml vs. metodi del dom per una tabella)