freeCodeCamp/curriculum/challenges/chinese-traditional/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++;