Files
2022-03-23 15:22:04 +01:00

1.2 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244ad 數字遞減 1 https://scrimba.com/c/cM2KeS2 17558 decrement-a-number-with-javascript

--description--

使用自減符號 --,你可以很方便地對一個變量執行自減或者 -1 運算。

i--;

等效於:

i = i - 1;

注意:i--; 這種寫法省去了書寫等號的必要。

--instructions--

修改代碼,使用 -- 符號對 myVar 執行自減操作。

--hints--

myVar 應該等於10

assert(myVar === 10);

應該修改 myVar = myVar - 1;

assert(!code.match(/myVar\s*=\s*myVar\s*[-]\s*1.*?;?/));

你不應將 10 分配給 myVar

assert(!code.match(/myVar\s*=\s*10.*?;?/));

應該對 myVar 使用 -- 運算符。

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

你不應該修改註釋上面的代碼。

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

--seed--

--after-user-code--

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

--seed-contents--

let myVar = 11;

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

--solutions--

let myVar = 11;
myVar--;