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

1.6 KiB

id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244ed 將變量追加到字符串 1 https://scrimba.com/c/cbQmZfa 16656 appending-variables-to-strings

--description--

就像我們可以用多行字符串字面量構建單個字符串一樣,我們還可以使用加且賦值(+=)運算符將字符串追加到字符串的末尾。

示例:

var anAdjective = "awesome!";
var ourStr = "freeCodeCamp is ";
ourStr += anAdjective;

ourStr 值爲 freeCodeCamp is awesome!

--instructions--

someAdjective 設置爲一個至少包含 3 個字符的字符串,然後使用 += 運算符將它追加到 myStr

--hints--

someAdjective 應當爲包含至少三個字符的字符串。

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

你應該使用 += 運算符將 someAdjective 追加到 myStr

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

var someAdjective;
var myStr = "Learning to code is ";

--solutions--

var someAdjective = "neat";
var myStr = "Learning to code is ";
myStr += someAdjective;