2016-07-25 25 views
-4
var quotePt1 = "Excellence is an art won by training and  
       habituation."; 
var quotePt2 = "We do not act rightly because we have virtue or  
       excellence,"; 
var quotePt3 = "but we rather have those because we have acted 
       rightly."; 
var quotePt4 = "We are what we repeatedly do."; 
var quotePt5 = "Excellence, then, is not an act but a habit."; 
var qouteFull = quotePt1.concat(quotePt2+quotePt3+quotePt4+quotePt5); 

Ich versuche, die volle Zitat Namen zuweisen sein ‚quoteFull‘ und drucken Sie dann das gesamte AngebotIch habe Probleme Druck einige verketteten Strings in Javascript

+1

können Sie durch '+' Zeichen – uzaif

+0

verketten? Wo ist dein Druckcode? Und was ist das Problem? – Bergi

+1

@uzaif oder von ['concat'] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat) – Bergi

Antwort

0

Ich bin mir nicht sicher, ob Sie sind sich Ihrer ganzen Rechtschreibfehler bewusst.

Putting das beiseite, warum nicht einfach verketten sie mit +, anstatt concat() zu verwenden?

var quotePt1 = "Excellence is an art won by training and habituation. "; 
 

 
var quotePt2 = "We do not act rightly because we have virtue or excellence, "; 
 

 
var quotePt3 = "but we rather have those because we have acted rightly. "; 
 

 
var quotePt4 = "We are what we repeatedly do. "; 
 

 
var quotePt5 = "Excellence, then, is not an act but a habit."; 
 

 
var qouteFull = quotePt1 + quotePt2 + quotePt3 + quotePt4 + quotePt5; 
 

 
console.log(qouteFull);

0

Wie die anderen Befragten antworteten, Strings in JavaScript verketten, verwenden Sie die +.

jedoch die Variablen mit einem aufsteigenden Integer namens sehen aus wie ein Array zu mir, und es könnte wie so codiert werden:

var quotePts = ["Excellence is an art won by training and habituation.", 
    "We do not act rightly because we have virtue or excellence,", 
    "but we rather have those because we have acted rightly.", 
    "We are what we repeatedly do.", 
    "Excellence, then, is not an act but a habit."]; 
var quoteFull = quotePts.join("\n",quotePts); 
console.log(quoteFull); 

Für Vollständigkeit, wenn Sie eine mehrzeilige Zeichenfolge verwenden mögen, können Sie ein umgekehrter Schrägstrich am Ende jeder Zeile, so wie:

var quoteFull = "Excellence is an art won by training and habituation. \n\ 
We do not act rightly because we have virtue or excellence, \n\ 
but we rather have those because we have acted rightly. \n\ 
We are what we repeatedly do. \n\ 
Excellence, then, is not an act but a habit."; 
console.log(quoteFull); 

Credit: https://davidwalsh.name/multiline-javascript-strings

0
var quotePt1 = "Excellence is an art won by training and habituation."; 
var quotePt2 = " We do not act rightly because we have virtue or  
       excellence,"; 
var quotePt3 = " but we rather have those because we have acted 
       rightly."; 
var quotePt4 = " We are what we repeatedly do."; 
var quotePt5 = " Excellence, then, is not an act but a habit."; 
var quoteFull = quotePt1 + quotePt2 + quotePt3 + quotePt4 + quotePt5; 

console.log (ZitatFull);

Dies ist die richtige Antwort. FYI. Ich musste nur meine Rechtschreibung korrigieren und ein Leerzeichen zwischen den Zeilen nach dem ersten Zitat einfügen. Ich arbeite an einem BLOC-Software-Entwicklerkurs und ich denke, der Kurs ist sehr spezifisch in Bezug auf Syntax. Wütend!