freeCodeCamp/curriculum/challenges/italian/02-javascript-algorithms-an.../basic-javascript/concatenating-strings-with-...

1.7 KiB

id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244b8 Concatenare le stringhe con l'operatore += 1 https://scrimba.com/c/cbQmmC4 16803 concatenating-strings-with-the-plus-equals-operator

--description--

Possiamo anche usare l'operatore += per concatenare una stringa alla fine di una variabile stringa esistente. Questo può essere molto utile per rompere una stringa lunga su diverse righe.

Nota: Attenzione agli spazi. La concatenazione non aggiunge spazi tra le stringhe concatenate, quindi dovrai aggiungerli da solo.

Esempio:

let ourStr = "I come first. ";
ourStr += "I come second.";

ourStr ora ha un valore stringa I come first. I come second..

--instructions--

Costruisci myStr su diverse righe concatenando queste due stringhe: This is the first sentence. e This is the second sentence. usando l'operatore +=. Usa l'operatore += in modo simile a quello mostrato nell'esempio e assicurati di includere uno spazio tra le due stringhe. Inizia assegnando la prima stringa a myStr, quindi aggiungi la seconda.

--hints--

myStr dovrebbe avere un valore stringa This is the first sentence. This is the second sentence.

assert(myStr === 'This is the first sentence. This is the second sentence.');

Dovresti usare l'operatore += per costruire myStr.

assert(code.match(/myStr\s*\+=\s*(["']).*\1/g));

--seed--

--after-user-code--

(function(){
  if(typeof myStr === 'string') {
    return 'myStr = "' + myStr + '"';
  } else {
    return 'myStr is not a string';
  }
})();

--seed-contents--

let myStr;

--solutions--

let myStr = "This is the first sentence. ";
myStr += "This is the second sentence.";