1.9 KiB
1.9 KiB
id, challengeType, videoUrl, forumTopicId, localeTitle
id | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244b9 | 1 | https://scrimba.com/c/cqk8rf4 | 16805 | 用变量构造字符串 |
Description
+
,你可以插入一个或多个变量来组成一个字符串。
Instructions
myName
,然后把变量myName
插入到字符串"My name is "
和" and I am well!"
之间,并把连接后的结果赋值给变量myStr
。
Tests
tests:
- text: <code>myName</code>至少要包含三个字符。
testString: assert(typeof myName !== 'undefined' && myName.length > 2);
- text: 使用两个<code>+</code>操作符创建包含<code>myName</code>的<code>myStr</code>变量。
testString: assert(code.match(/["']\s*\+\s*myName\s*\+\s*["']/g).length > 0);
Challenge Seed
// Example
var ourName = "freeCodeCamp";
var ourStr = "Hello, our name is " + ourName + ", how are you?";
// Only change code below this line
var myName;
var myStr;
After Test
(function(){
var output = [];
if(typeof myName === 'string') {
output.push('myName = "' + myName + '"');
} else {
output.push('myName is not a string');
}
if(typeof myStr === 'string') {
output.push('myStr = "' + myStr + '"');
} else {
output.push('myStr is not a string');
}
return output.join('\n');
})();
Solution
var myName = "Bob";
var myStr = "My name is " + myName + " and I am well!";