valtzy
Registered User regular

Help!

I have the following javascript program

<html>

<head><title>Multiplication Table</title></head>

<body><center><h1><u>Multiplication Tables</h1> (Positive/Negative numbers)</u></center>

<p>

<center><h1>Positive Numbers</h1></center>

<script language="JavaScript">

for(x=1;x<=3;x++)

for(y=1;y<=3;y++)

{document.writeln("<br>",x,"*",y,"=",y*x)}

document.writeln("<hr>")

document.writeln("<center><h1>Negative Numbers</h1></center>")

for(x=1;x<=3;x++)

for(y=1;y<=3;y++)

{document.writeln("<br>",-x,"*",y,"=",y*-x,"<hr>")}

</script>

I need to insert horizontal rules (<hr>) in between blocks of three.

1*1=1

1*2=2

1*3=3

2*1=2

2*2=4

2*3=6

3*1=3

3*2=6

3*3=9

the loop puts it after every line though. What am I doing wrong?

I have the following javascript program

<html>

<head><title>Multiplication Table</title></head>

<body><center><h1><u>Multiplication Tables</h1> (Positive/Negative numbers)</u></center>

<p>

<center><h1>Positive Numbers</h1></center>

<script language="JavaScript">

for(x=1;x<=3;x++)

for(y=1;y<=3;y++)

{document.writeln("<br>",x,"*",y,"=",y*x)}

document.writeln("<hr>")

document.writeln("<center><h1>Negative Numbers</h1></center>")

for(x=1;x<=3;x++)

for(y=1;y<=3;y++)

{document.writeln("<br>",-x,"*",y,"=",y*-x,"<hr>")}

</script>

I need to insert horizontal rules (<hr>) in between blocks of three.

1*1=1

1*2=2

1*3=3

2*1=2

2*2=4

2*3=6

3*1=3

3*2=6

3*3=9

the loop puts it after every line though. What am I doing wrong?

0

## Posts

Edit edit: I see, now. Listen to the guy below me.

Thor1590onYou will see that each for loop contains braces to indicate the scope for the command. If you do not provide braces then the "next line" is the only line that has scope for that loop. A good "rule of thumb" is to always provide matching braces for loops (even if you have only one line to execute). It does not add anything to the overhead and potentially makes the code easier to read.

I would also suggest a style change, to make it easier to see what code is in what loop (again a personal preference.. You do not HAVE to do this).

Bigtoy_JonAlso, I can count to "boat".