//problem resolved//Displaying random quotes

(Excuse me, I don’t know how to finalize the discussion…)

I’m really a beginner (and old ha ha ha)
I found some programming that allows me to display random sentences from HTML. The code is fine after some reflections and adaptations I am trying to make a line BREAK in a variable so that the name of the creator of the quote is after the sentence, below.

For example and simplified, a sentence:
“So shaken as we are, so wan with care,” Henry announces to his court. Shakespeare"
I would like this:
“So shaken as we are, so wan with care, Henry announces to his court.” (on line return…)
“Shakespeare”
I can’t find…
The code used (which I did not create comes from a codePen site. The script.js gives this and works (in short) but not possible to find a line break

var quotes = ["So shaken as we are, so wan with care," Henry announces to his court. Shakespeare",

"To be, or not to be: that is the question.  Shakespeare"
]; etc. etc.

function getQuote() {
var randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
document.getElementById("parag").innerHTML="<em>" + randomQuote + "</em>";
}

Well there’s two different things there.

A break in the string is easily enough doable with the return button on your keyboard.
A break in the string that shows up in rendered HTML would require the html line break element, <br>.
Alternatively, wrapping the first part of the quote in a paragraph element (<p>) would accomplish the line break (and probably be closer to “correct” syntax).

I’m not very familiar with programming. what I have in my HTML page is this.

<body>
    <div id="quotecontainer">
    
	<p class="lead" id="parag"><em>Citations du roman.</em><br><br>
    <i class="pull-right"></i></p>
    
	<!-- origine -->
	<!-- <button onclick="getQuote()" type="button" id="btn-bottom-right" class="btn btn-primary btn-large pull-right">Autre citation</button> -->
    
	<!-- modif -->
	<button onclick="getQuote()" type="button" id="btn-bottom-right" class="btn btn-primary btn-large pull-right">HTDAP Quelques citations</button>

	
	
	<!-- <button onclick="shareQuote()" type="button" id="btn-bottom-left" class="fa fa-twitter"></button> -->
    </div>
  </html>
<!-- partial -->
  <script  src="./script.js"></script>
</body>

So to code in paragraph or in
I don’t see how to insert it in my script.js?

Since we are dealing with quotes, maybe <blockquote> and <cite> would be more appropriate.

@m_hutley seems to be correct, just br should do the trick.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.