2
<!DOCTYPE html>
<html>

<head>
    <title>multiplication table</title>
</head>

<body>
    <script type="text/javascript">
    var i, j;
    var m = 1;

    for (i = 1; i <= 10; i++) {
        for (j = 1; j <= 10; j++) {
            document.write(i * j);
        }
        document.write("\n");
    }
    </script>
</body>

</html>

Output:

12345678910 2468101214161820 36912151821242730 481216202428323640 5101520253035404550 6121824303642485460 7142128354249566370 8162432404856647280 9182736455463728190 102030405060708090100

it gives output without printing the new line. I want to execute this without using

7 Answers 7

5

Use <br /> to print text on new line. When you are putting the content in DOM. \n will just add a space instead of newline.

document.write("<br />");

Example:

var i, j;
var m = 1;

for (i = 1; i <= 10; i++) {
  for (j = 1; j <= 10; j++) {
    document.write(i * j);
  }
  document.write("<br />");
}

Sign up to request clarification or add additional context in comments.

Comments

3

Instead of document.write("\n"); in your code add document.write("

Code Goes here -

<!DOCTYPE html>
<html>
<head>
    <title>multiplication table</title>
</head>

<body>
    <script type="text/javascript">
    var i, j;
    var m = 1;

    for (i = 1; i <= 10; i++) {
        for (j = 1; j <= 10; j++) {
            document.write(i * j);
        }
        document.write("<br/>");
    }
    </script>
</body>

</html>

Comments

2

var i, j;
var m = 1;

for (i = 1; i <= 10; i++) {
  for (j = 1; j <= 10; j++) {
    document.write(i * j + "\n\n");
  }
  document.write("<br />");
}

Comments

1

if you goes with patterns in js :process.stdout.write(''); for print them to next line

Comments

0

Replace document.write("\n"); with document.write("<br />");

See the fiddle: "https://jsfiddle.net/godcb7L2/"

Comments

0
<html>
<body>
  <script type="text/javascript">
     var i, j;
     var m = 1;
      for (i = 1; i <= 10; i++) {
       for (j = 1; j <= 10; j++) {
       document.write(i * j);
       }
      document.write("<br />");
     }
  </script>
</body>
</html>

Comments

0

Did you try <br/>, <br><br/>? <br> should be supported according to this source, though.

Like: document.write("<br/>")

Supported HTML tags

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.