To input text onto a webpage via javascript, I have created the following script:
// Creating name as h1
var h = document.createElement('h1');
var t = document.createTextNode('Jane Doe');
h.appendChild(t);
document.body.appendChild(h);
// Formatting h1 tag
document.querySelector('h1').style.color = 'blue';
document.querySelector('h1').style.fontFamily = 'Verdana';
document.querySelector('h1').style.textAlign = 'center';
// Line break
document.write('\n');
// Creating course and section number as h2
var h_2 = document.createElement('h2');
var t_2 = document.createTextNode('WEB 101 - Section 0010');
h_2.appendChild(t_2);
document.body.appendChild(h_2);
// Formatting h2 tag
document.querySelector('h2').style.color = 'blue';
document.querySelector('h2').style.fontFamily = 'Arial';
document.querySelector('h2').style.fontStyle = 'italic';
document.querySelector('h2').style.textAlign = 'center';
document.write('\n');
simply adds a small space between my text "Jane Doe" and "WEB 101 - Section 0010," not an actual line break.
The desired output should appear like this:
Jane Doe
WEB 101 - Section 0010
However, the current output displays like this:
Jane Doe WEB 101 - Section 0010
Is there a way to insert a line break in this scenario?