Help with newlines in quotes

I am displaying a quote and need a newline to be added after the quote.

So…

“It is said that the real winner is the one who lives in today but able to see tomorrow. --Juan Meng”

Needs to look like:

“It is said that the real winner is the one who lives in today but able to see tomorrow.
–Juan Meng”

How would I do this? I tired \n in the string and that didn’t add a newline.

Have you tried
(The line break) ?

<p>“It is said that the real winner is the one who lives in today but able to see tomorrow. <br>--Juan Meng”</p>

1 Like
Use innerText instead of innerHTML. Or use <br> instead of \n.
function btnClick() {
  var randomQuote = Math.floor(Math.random() * quoteListLength);
  var current = quoteList[randomQuote];
  // innerText is safer
  mess.innerText = current.quote + '\n--' + current.author;
  // But if you must use innerHTML
  // mess.innerHTML = current.quote + '<br />--' + current.author;
}

var mess = document.getElementById('messy');

var quoteList = {
  0: {
    quote:
      "Don't worry about what anybody else is going to do. The best way to predict the future is to invent it.",
    author: 'Alan Kay'
  },
  1: {
    quote:
      'Premature optimization is the root of all evil (or at least most of it) in programming.',
    author: 'Donald Knuth'
  },
  2: {
    quote:
      'Lisp has jokingly been called the most intelligent way to misuse a computer. I think that description is a great compliment because it transmits the full flavor of liberation: it has assisted a number of our most gifted fellow humans in thinking previously impossible thoughts.',
    author: 'Edsger Dijkstra'
  },
  3: {
    quote:
      'Keep away from people who try to belittle your ambitions. Small people always do that, but the really great make you feel that you, too, can become great.',
    author: 'Mark Twain'
  },
  4: {
    quote:
      "What Paul does, and does very well, is to take ideas and concepts that are beautiful in the abstract, and brings them down to a real world level. That's a rare talent to find in writing these days.",
    author: 'Jeff Bates, Director, OSDN; Co-evolver, Slashdot'
  },
  5: {
    quote:
      'Since programmers create programs out of nothing, imagination is our only limitation. Thus, in the world of programming, the hero is the one who has great vision. Paul Graham is one of our contemporary heroes. He has the ability to embrace the vision, and to express it plainly. His works are my favorites, especially the ones describing language design. He explains secrets of programming, languages, and human nature that can only be learned from the hacker experience. This book shows you his great vision, and tells you the truth about the nature of hacking.',
    author: 'Yukihiro Matsumoto, creator of Ruby'
  },
  6: {
    quote:
      'To follow the path: look to the master, follow the master, walk with the master, see through the master, become the master.',
    author: 'Modern zen Poem'
  },
  7: {
    quote: 'No problem should ever have to be solved twice.',
    author: 'Eric S. Raymond, How to become a hacker'
  },
  8: {
    quote: 'Attitude is no substitute for competence.',
    author: 'Eric S. Raymond, How to become a hacker'
  },
  9: {
    quote:
      'It is said that the real winner is the one who lives in today but able to see tomorrow.',
    author: 'Juan Meng'
  }
};

var quoteListLength = Object.keys(quoteList).length;

Impress your friends
const btnClick = () => m.innerText=l[floor(random()*l.length)].join('\n--')

const l = [["Don't worry about what anybody else is going to do. The best way to predict the future is to invent it.",'Alan Kay'],
  ['Premature optimization is the root of all evil (or at least most of it) in programming.','Donald Knuth'],
  ['Lisp has jokingly been called the most intelligent way to misuse a computer. I think that description is a great compliment because it transmits the full flavor of liberation: it has assisted a number of our most gifted fellow humans in thinking previously impossible thoughts.','Edsger Dijkstra'],
  ['Keep away from people who try to belittle your ambitions. Small people always do that, but the really great make you feel that you, too, can become great.','Mark Twain'],
  ["What Paul does, and does very well, is to take ideas and concepts that are beautiful in the abstract, and brings them down to a real world level. That's a rare talent to find in writing these days.",'Jeff Bates, Director, OSDN; Co-evolver, Slashdot'],
  ['Since programmers create programs out of nothing, imagination is our only limitation. Thus, in the world of programming, the hero is the one who has great vision. Paul Graham is one of our contemporary heroes. He has the ability to embrace the vision, and to express it plainly. His works are my favorites, especially the ones describing language design. He explains secrets of programming, languages, and human nature that can only be learned from the hacker experience. This book shows you his great vision, and tells you the truth about the nature of hacking.','Yukihiro Matsumoto, creator of Ruby'],
  ['To follow the path: look to the master, follow the master, walk with the master, see through the master, become the master.','Modern zen Poem'],
  ['No problem should ever have to be solved twice.','Eric S. Raymond, How to become a hacker'],
  ['Attitude is no substitute for competence.','Eric S. Raymond, How to become a hacker'],
  ['It is said that the real winner is the one who lives in today but able to see tomorrow.','Juan Meng']], m=document.getElementById('messy'),{floor,random}=Math
1 Like