0

I'm trying to use a template string to update infoDiv's text and for some reason all this text is in one line. What am I doing wrong? None of these solutions work - they're just rendered.

infoDiv.textContent = `Hi!
It's a ${counter} question quiz.
It takes about ${time_minutes} minutes to solve it.
Are you ready?`

EDIT:

I found a CSS solution here (white-space: pre-line;).

let counter = 8;
let time_minutes = 3;

infoDiv.textContent = `Hi!
It's a ${counter} question quiz.
It takes about ${time_minutes} minutes to solve it.
Are you ready?`
<div id="infoDiv" style="white-space: pre-line"></div>
Community
  • 1
  • 1
Anna
  • 17
  • 6

1 Answers1

5

Style the div with white-space CSS property.

const counter = 22;
const time_minutes = 60;

infoDiv.textContent = `Hi!
It's a ${counter} question quiz.
It takes about ${time_minutes} minutes to solve it.
Are you ready?`
<div id="infoDiv" style="white-space: pre-wrap"></div>