Valeriy 79d9012432 fix(curriculum): quotes in tests (#18828)
* fix(curriculum): tests quotes

* fix(curriculum): fill seed-teardown

* fix(curriculum): fix tests and remove unneeded seed-teardown
2018-10-20 23:32:47 +05:30

2.1 KiB

id, title, challengeType
id title challengeType
56533eb9ac21ba0edf2244af Compound Assignment With Augmented Addition 1

Description

In programming, it is common to use assignments to modify the contents of a variable. Remember that everything to the right of the equals sign is evaluated first, so we can say: myVar = myVar + 5; to add 5 to myVar. Since this is such a common pattern, there are operators which do both a mathematical operation and assignment in one step. One such operator is the += operator.
var myVar = 1;
myVar += 5;
console.log(myVar); // Returns 6

Instructions

Convert the assignments for a, b, and c to use the += operator.

Tests

tests:
  - text: <code>a</code> should equal <code>15</code>
    testString: assert(a === 15, '<code>a</code> should equal <code>15</code>');
  - text: <code>b</code> should equal <code>26</code>
    testString: assert(b === 26, '<code>b</code> should equal <code>26</code>');
  - text: <code>c</code> should equal <code>19</code>
    testString: assert(c === 19, '<code>c</code> should equal <code>19</code>');
  - text: You should use the <code>+=</code> operator for each variable
    testString: assert(code.match(/\+=/g).length === 3, 'You should use the <code>+=</code> operator for each variable');
  - text: Do not modify the code above the line
    testString: assert(/var a = 3;/.test(code) && /var b = 17;/.test(code) && /var c = 12;/.test(code), 'Do not modify the code above the line');

Challenge Seed

var a = 3;
var b = 17;
var c = 12;

// Only modify code below this line

a = a + 12;
b = 9 + b;
c = c + 7;

After Test

(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = " + c; })(a,b,c);

Solution

var a = 3;
var b = 17;
var c = 12;

a += 12;
b += 9;
c += 7;