freeCodeCamp/curriculum/challenges/italian/02-javascript-algorithms-an.../basic-javascript/appending-variables-to-stri...

1.6 KiB

id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244ed Aggiungere variabili alle stringhe 1 https://scrimba.com/c/cbQmZfa 16656 appending-variables-to-strings

--description--

Proprio come possiamo costruire una stringa su più righe di stringhe letterali, possiamo anche aggiungere delle variabili a una stringa usando l'operatore +=.

Esempio:

const anAdjective = "awesome!";
let ourStr = "freeCodeCamp is ";
ourStr += anAdjective;

ourStr avrà il valore freeCodeCamp is awesome!.

--instructions--

Imposta someAdjective a una stringa di almeno 3 caratteri e aggiungila a myStr utilizzando l'operatore +=.

--hints--

someAdjective dovrebbe essere impostato su una stringa lunga almeno 3 caratteri.

assert(typeof someAdjective !== 'undefined' && someAdjective.length > 2);

Dovresti aggiungere someAdjective a myStr usando l'operatore +=.

assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0);

--seed--

--after-user-code--

(function(){
  var output = [];
  if(typeof someAdjective === 'string') {
    output.push('someAdjective = "' + someAdjective + '"');
  } else {
    output.push('someAdjective is not a string');
  }
  if(typeof myStr === 'string') {
    output.push('myStr = "' + myStr + '"');
  } else {
    output.push('myStr is not a string');
  }
  return output.join('\n');
})();

--seed-contents--

// Change code below this line
const someAdjective = "";
let myStr = "Learning to code is ";

--solutions--

const someAdjective = "neat";
let myStr = "Learning to code is ";
myStr += someAdjective;