2.2 KiB
2.2 KiB
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244b7 | 文字列をプラス演算子で連結する | 1 | https://scrimba.com/c/cNpM8AN | 16802 | concatenating-strings-with-plus-operator |
--description--
JavaScript では、+
演算子を String
の値に対して使用する場合、その演算子のことを連結演算子と呼びます。 他の文字列を一緒に連結することで新しい文字列を作ることができます。
例
'My name is Alan,' + ' I concatenate.'
注: 空白が必要な場合は注意してください。 連結では、文字列の間に空白が追加されないため、必要な場合は自分で付け加える必要があります。
例:
const ourStr = "I come first. " + "I come second.";
コンソールに、文字列 I come first. I come second.
が表示されます。
--instructions--
+
演算子を使用して、文字列 This is the start.
と This is the end.
から myStr
を作成してください。 2 つの文字列の間に空白を必ず含めるようにしてください。
--hints--
myStr
は、2 つの文字列の間に空白文字を含む必要があります。
assert(/start\. This/.test(myStr));
myStr
は、文字列の値 This is the start. This is the end.
を持つ必要があります。
assert(myStr === 'This is the start. This is the end.');
+
演算子を使用して myStr
を作成する必要があります。
assert(code.match(/(["']).*\1\s*\+\s*(["']).*\2/g));
const
キーワードを使用して myStr
を作成する必要があります。
assert(/const\s+myStr/.test(code));
結果を myStr
変数に代入する必要があります。
assert(/myStr\s*=/.test(code));
--seed--
--after-user-code--
(function(){
if(typeof myStr === 'string') {
return 'myStr = "' + myStr + '"';
} else {
return 'myStr is not a string';
}
})();
--seed-contents--
const myStr = ""; // Change this line
--solutions--
const myStr = "This is the start. " + "This is the end.";