"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."
En anders:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| x = 3;
y = 5;
str = '<table border="1">';
for (var i = 0; i < y; i++)
{
str = str + '<tr>';
for (var j = 0; j < x; j++)
{
str = str + '<td>' + j + (j * i) +'</td>';
}
str = str + '</tr>';
}
str = str + '</table>';
document.write(str); |
Uit de losse pols.
[ Voor 68% gewijzigd door André op 14-09-2004 17:28 ]
Verwijderd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| function createTable(arInput, iWidth) { var sOutput = '<table>'; for(var i = 0; (i * iWidth) < arInput.length; i++) { sOutput += "<tr>"; for(var j = 0 ; j < iWidth; j++) { if(j < arInput.length) sOutput += "<td>"+arInput[i*iWidth+j]+"</td>"; else sOutput += "<td></td>"; } sOutput += "</tr>"; } sOutput += "</table>"; return sOutput; } |
[ Voor 64% gewijzigd door Verwijderd op 14-09-2004 17:28 . Reden: kleine typo ]
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
26
27
28
29
| var characterList = new Array( "£", "€", "©", "®", "±", "·", "¼", "½", "¾", "Ä", "ä", "Ë", "ë", "Ü", "ü", "Ï", "ï", "Ö", "ö", "§", "ç"); function createTable(arInput, iWidth) { var sOutput = '<table border=1>'; for (var i = 0; (i * iWidth) < arInput.length; i++) { sOutput += "<tr>"; for (var j = 0 ; j < iWidth; j++) { if(j < arInput.length) sOutput += "<td>"+arInput[i*iWidth+j]+"</td>"; else sOutput += "<td></td>"; } sOutput += "</tr>"; } sOutput += "</table>"; return sOutput; } document.write(createTable(characterList, 4)); |
De tabel die hier gevormd wordt heeft in de laatste rij drie cellen met 'undefined' erin. Dat komt omdat er geen teller is die bijhoudt welk element van de array we aan het verwerken zijn. Hier gaat het fout:
1
| if(j < arInput.length) |
j moet hier vervangen worden door een teller zoals hierboven beschreven. Ik heb o.a. geprobeerd:
1
| if(((j+1)*(i+1))) < arInput.length) |
(rijen * cellen), maar dit levert een merkwaardig resultaat op. Ook alternatieven hierop schijnen niet te werken. Wie heeft een oplossing?
"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."
1
2
3
4
5
6
7
8
9
10
11
12
| kolommen = 3;
cellen = 15;
str = '<table border="1"><tr>';
for (var i = 0; i <= cellen; i++)
{
str = str + '<td>' + i + '</td>';
if ((i + 1) % kolommen == 0) { str = str + '</tr><tr>' };
}
str = str + '</table>';
document.write(str); |
% (modulo) betekent toch "blijft er iets over"? Met andere woorden: 5 % 2 = 1 en 8 % 3 = 2? Als dat zo is, kan ik je code verder analyseren en kan ik nog eens naar mijn begin kijken waarom dat helemaal voud ging...
"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."