2018-10-10 18:03:03 -04:00
---
id: 56533eb9ac21ba0edf2244b9
title: Constructing Strings with Variables
challengeType: 1
videoUrl: ''
localeTitle: 用变量构造字符串
---
## Description
< section id = "description" > 有时您需要构建一个字符串, < a href = "https://en.wikipedia.org/wiki/Mad_Libs" target = "_blank" > Mad Libs< / a > 样式。通过使用连接运算符( < code > +< / code > ),您可以将一个或多个变量插入到正在构建的字符串中。 < / section >
## Instructions
< section id = "instructions" > 将< code > myName< / code > 设置为等于您的名字的字符串,并在字符串< code > " My name is " < / code > 和< code > " and I am well!" < / code > 之间用< code > myName< / code > 构建< code > myStr< / code > < code > " and I am well!" < / code > < / section >
## Tests
< section id = 'tests' >
```yml
tests:
- text: < code > myName</ code > 应设置为至少3个字符长的字符串
2020-02-18 01:40:55 +09:00
testString: assert(typeof myName !== 'undefined' & & myName.length > 2);
2018-10-10 18:03:03 -04:00
- text: 使用两个< code > +</ code > 运算符在其中构建< code > myStr</ code > with < code > myName</ code >
2020-02-18 01:40:55 +09:00
testString: assert(code.match(/["']\s*\+\s*myName\s*\+\s*["']/g).length > 0);
2018-10-10 18:03:03 -04:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
// Example
var ourName = "freeCodeCamp";
var ourStr = "Hello, our name is " + ourName + ", how are you?";
// Only change code below this line
var myName;
var myStr;
```
< / div >
### After Test
< div id = 'js-teardown' >
```js
console.info('after the test');
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
// solution required
```
< / section >