1.6 KiB
1.6 KiB
id, title, challengeType, videoUrl, forumTopicId, localeTitle
id | title | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244ad | Decrement a Number with JavaScript | 1 | https://scrimba.com/c/cM2KeS2 | 17558 | 数字递减 |
Description
--
,你可以很方便地对一个变量执行自减或者-1
运算。
i--;
等效于
i = i - 1;
提示i--;
这种写法,省去了书写=
符号的必要。
Instructions
--
符号对myVar
执行自减操作。
Tests
tests:
- text: <code>myVar</code>应该等于<code>10</code>。
testString: assert(myVar === 10);
- text: <code>myVar = myVar - 1;</code>语句应该被修改。
testString: assert(/var\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code));
- text: 对<code>myVar</code>使用<code>--</code>运算符。
testString: assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code));
- text: 不要修改注释上面的代码。
testString: assert(/var myVar = 11;/.test(code));
Challenge Seed
var myVar = 11;
// Only change code below this line
myVar = myVar - 1;
After Test
(function(z){return 'myVar = ' + z;})(myVar);
Solution
var myVar = 11;
myVar--;