Salve a tutti! Secondo un esercizio del mio prof di informatica, devo realizzare in javascript una pagina dove inserendo il numero di colonne e righe venga creata una matrice di numeri casuali e successivamente scritta in una tabella. E' tutto il giorno che mi scervello sul codice ma sono in un punto mortoDove sbaglio??
<!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">
<head>
<title>Esercizio sulle Matrici N°1</title>
<style type="text/css">
.style1
{
width: 19px;
}
</style>
<script type="text/javascript" language="javascript">
function matrice(a, b) {
var mat = new Array(b);
for (var i = 0; i < mat.length; i++)
mat[i] = new Array(a);
return mat;
}
function valoricas(v) {
for (var i = 0; i < v.length; i++) {
for (var j = 0; j < v[i].lenght; j++) {
v[i][j] = parseInt(Math.random() * 100);
}
}
return v;
}
function scrivere(mat) {
for (var i = 0; i < mat.length; i++) {
document.write("
");
for (var j = 0; j < mat[i].length; j++) document.write(mat[i][j] + ",");
}
}
/* function scrivere(v) {
document.write("<table>");
for (var i = o; i < righe; i++) {
document.write("<tr>");
for (var j = 0; j < colonne; j++) {
document.write("<td>" + v[i][j] + "</td>");
}
document.write("</tr>");
} document.write("</table>");
}
*/
function main() {
righe = parseInt(rig.value);
colonne = parseInt(col.value);
v = matrice(colonne, righe);
valoricas(v);
scrivere(v);
}
</script>
</head>
<body>
Colonne della matrice:
<table cellpadding="0" cellspacing="0" id="tab1">
<tr>
<td rowspan="3" height="100%" valign="bottom" class="style1">
<input type='text' id='col' value='0' style="width: 20px; height: 33px">
</td>
</tr>
<tr>
<td valign="bottom">
<input type='button' value='^' onclick='col.value++;' style="height: 20px;">
</td>
</tr>
<tr>
<td valign="top">
<input type='button' value='v' onclick='col.value--;' style="height: 20px;">
</td>
</tr>
</table>
Righe della matrice:
<table cellpadding="0" cellspacing="0">
<tr>
<td rowspan="3" height="100%" valign="bottom" class="style1">
<input type='text' id='rig' value='0' style="width: 20px; height: 33px">
</td>
</tr>
<tr>
<td valign="bottom">
<input type='button' value='^' onclick='rig.value++;' style="height: 20px;">
</td>
</tr>
<tr>
<td valign="top">
<input type='button' value='v' onclick='rig.value--;' style="height: 20px;">
</td>
</tr>
</table>
<input id="Bu" type="button" value="Cliccami" onclick="main()" />
</body>
</html>
Grazie in anticipo per l'aiuto![]()