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 should equal 88.

assert(myVar === 88);

不应该使用赋值运算符。

assert(
  /var\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(/var myVar = 87;/.test(code));

--seed--

--after-user-code--

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

--seed-contents--

var myVar = 87;

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

--solutions--

var myVar = 87;
myVar++;