freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../basic-javascript/increment-a-number-with-jav...

1.1 KiB

id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244ac 数字递增 1 https://scrimba.com/c/ca8GLT9 18201 increment-a-number-with-javascript

--description--

使用 ++,我们可以很容易地对变量进行自增或者 +1 运算。

i++;

等效于:

i = i + 1;

注意:i++; 这种写法省去了书写等号的必要。

--instructions--

修改代码,使用 ++ 来对变量 myVar 进行自增操作。

--hints--

myVar 应该等于 88

assert(myVar === 88);

不应该使用赋值运算符。

assert(
  /let\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code)
);

应该使用 ++ 运算符。

assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code));

不应该修改注释上面的代码。

assert(/let myVar = 87;/.test(code));

--seed--

--after-user-code--

(function(z){return 'myVar = ' + z;})(myVar);

--seed-contents--

let myVar = 87;

// Only change code below this line
myVar = myVar + 1;

--solutions--

let myVar = 87;
myVar++;