2

This is a snippet of code, I want to add a line break after each statement. Tried using "/r/n" and "<-br>" none of them seem to work fine.

**else {
    para.textContent = num + ' squared is ' + squared(num) + '. ' +
    num + ' cubed is ' + cubed(num) + '. ' +
    num + ' factorial is ' + factorial(num) + '.';
      }**
EighthGod
  • 21
  • 1
  • 2

1 Answers1

2

Instead of textContent you can use innerHTML and <br />s.

para.innerHTML = num + ' squared is ' + squared(num) + '.<br />' +
    num + ' cubed is ' + cubed(num) + '.<br />' +
    num + ' factorial is ' + factorial(num) + '.';

You can also solve this using CSS. Just add this style white-space: pre; to the target element: para.setAttribute('style', 'white-space: pre;');

A. Meshu
  • 3,840
  • 2
  • 18
  • 32
Alvaro Castro
  • 771
  • 1
  • 7
  • 25