2020-10-06 23:10:08 +05:30

1.7 KiB

id, challengeType, videoUrl, forumTopicId, localeTitle
id challengeType videoUrl forumTopicId localeTitle
56533eb9ac21ba0edf2244ac 1 https://scrimba.com/c/ca8GLT9 18201 数字递增

Description

使用++,我们可以很容易地对变量进行自增或者+1运算。 i++; 等效于 i = i + 1; 注意
i++;这种写法,省去了书写=符号的必要。

Instructions

重写代码,使用++来对变量myVar进行自增操作。 提示
了解更多关于++运算符Arithmetic operators - Increment (++).

Tests

tests:
  - text: <code>myVar</code>应该等于<code>88</code>。
    testString: assert(myVar === 88);
  - text: <code>myVar = myVar + 1;</code>语句应该被修改。
    testString: assert(/var\s*myVar\s*=\s*87;\s*\/*.*\s*myVar\+\+;/.test(code));
  - text: 使用<code>++</code>运算符。
    testString: assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code));
  - text: 不要修改注释上方的代码。
    testString: assert(/var myVar = 87;/.test(code));

Challenge Seed

var myVar = 87;

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

After Test

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

Solution

var myVar = 87;
myVar++;