, 1 10.
var i, x = 0; for (i = 1; i <= 10; i++) {x += i} document.write(x) |
:
:
i , x. . - , Null ( , ).
1. 10 , 10. 1 ( ).
. , ++ +=, .
x += i x.
.
.
. document.write ( ). , :
var i, x = 0; for (i = 1; i <= 10; i++) {x += i document.write(x + "; ") } |
:
1; 3; 6; 10; 15; 21; 28; 36; 45; 55;
, , ,
if...else. i (10) , :
var i, x = 0; for (i = 1; i <= 10; i++) {x += i if (i == 10) {document.write(x + ". ")} else {document.write(x + "; ")} } |
:
1; 3; 6; 10; 15; 21; 28; 36; 45; 55.
: , , write writeln. writeln.
................ if (i == 10) {document.write(x + ". ")} else {document.writeln(x + "; ")}........ |
, .
, , . .
, , :
22=4 | 32=6 | 42=8 | 52=10 | 62=12 | 72=14 | 82=16 | 92=18 |
23=6 | 33=9 | 43=12 | 53=15 | 63=18 | 73=21 | 83=24 | 93=27 |
24=8 | 34=12 | 44=16 | 54=20 | 64=24 | 74=28 | 84=32 | 94=36 |
25=10 | 35=15 | 45=20 | 55=25 | 65=30 | 75=35 | 85=40 | 95=45 |
26=12 | 36=18 | 46=24 | 56=30 | 66=36 | 76=42 | 86=48 | 96=54 |
27=14 | 37=21 | 47=28 | 57=35 | 67=42 | 77=49 | 87=56 | 97=63 |
28=16 | 38=24 | 48=32 | 58=40 | 68=48 | 78=56 | 88=64 | 98=72 |
29=18 | 39=27 | 49=36 | 59=45 | 69=54 | 79=63 | 89=72 | 99=81 |
210=20 | 310=30 | 410=40 | 510=50 | 610=60 | 710=70 | 810=80 | 910=90 |
.
|
|
.
HTML, <tr>, , , <td>.
.
. .
. , .
<tr> ( 2 10), 8 ( 2 9).
<tr> i.
var i; for (i = 2; i <= 10; i++) {document.write(" <tr> "); document.write(" </tr> ")} |
2 10, 1 9?
...
, , 22.
<tr> (× HTML ):
<tr> <td>2 × 2=4</td> <td>3 × 2=6</td> <td>4 × 2=8</td> <td>5 × 2=10</td> <td>6 × 2=12</td> <td>7 × 2=14</td> <td>8 × 2=16</td> <td>9 × 2=18</td> </tr> |
</td>.
, if...else. ?
j.
var i, j; document.write(" <table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\"> ") for (i = 2; i <= 10; i++) {document.write(" <tr> "); for (j = 2; j < 10; j++) {document.write(" <td> " + " </td> ")} document.write(" </tr> ") } document.write(" </table> ") |
? i <= 10, j < 10 ( ), .
, . </td>, , j. , </tr>, i:
j + "×" + i + "=" + (i*j)
:
var i, j; document.write(" <table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\"> ") for (i = 2; i <= 10; i++) {document.write(" <tr> "); for (j = 2; j < 10; j++) {document.write(" <td> " + j + " × " + i + " = " + (i * j) + " </td> ")} document.write(" </tr> ") } document.write(" </table> ") |
. , , Unicode. . .