diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions.english.md
index 79c53d3e1c..2f89f21f1f 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions.english.md
@@ -23,11 +23,11 @@ Modify the function increment
by adding default parameters so that
```yml
tests:
- text: The result of increment(5, 2)
should be 7
.
- testString: assert(increment(5, 2) === 7, 'The result of increment(5, 2)
should be 7
.');
+ testString: assert(increment(5, 2) === 7);
- text: The result of increment(5)
should be 6
.
- testString: assert(increment(5) === 6, 'The result of increment(5)
should be 6
.');
- - text: default parameter 1
was used for value
.
- testString: getUserInput => assert(getUserInput('index').match(/value\s*=\s*1/g), 'default parameter 1
was used for value
.');
+ testString: assert(increment(5) === 6);
+ - text: Default parameter 1
was used for value
.
+ testString: assert(code.match(/value\s*=\s*1/g));
```
@@ -39,12 +39,8 @@ tests:
Vegetable
lets you create a vegetable object, with a property <
```yml
tests:
- text: Vegetable
should be a class
with a defined constructor
method.
- testString: assert(typeof Vegetable === 'function' && typeof Vegetable.constructor === 'function', 'Vegetable
should be a class
with a defined constructor
method.');
- - text: class
keyword was used.
- testString: getUserInput => assert(getUserInput('index').match(/class/g),'class
keyword was used.');
- - text: Vegetable
can be instantiated.
- testString: assert(() => {const a = new Vegetable("apple"); return typeof a === 'object';},'Vegetable
can be instantiated.');
+ testString: assert(typeof Vegetable === 'function' && typeof Vegetable.constructor === 'function');
+ - text: class
keyword should be used.
+ testString: assert(code.match(/class/g));
+ - text: Vegetable
should be able to be instantiated.
+ testString: assert(() => {const a = new Vegetable("apple"); return typeof a === 'object';});
- text: carrot.name
should return carrot
.
- testString: assert(carrot.name=='carrot','carrot.name
should return carrot
.');
+ testString: assert(carrot.name=='carrot');
```
@@ -47,14 +47,10 @@ tests:
a
and ba
should be 6, after swapping.
- testString: assert(a === 6, 'Value of a
should be 6, after swapping.');
+ testString: assert(a === 6);
- text: Value of b
should be 8, after swapping.
- testString: assert(b === 8, 'Value of b
should be 8, after swapping.');
- - text: Use array destructuring to swap a and b.
- testString: 'assert(/\[\s*(\w)\s*,\s*(\w)\s*\]\s*=\s*\[\s*\2\s*,\s*\1\s*\]/g.test(code), "Use array destructuring to swap a and b.");'
+ testString: assert(b === 8);
+ - text: Should use array destructuring to swap a and b.
+ testString: assert(/\[\s*(\w)\s*,\s*(\w)\s*\]\s*=\s*\[\s*\2\s*,\s*\1\s*\]/g.test(code));
```
@@ -43,12 +43,9 @@ tests:
```js
let a = 8, b = 6;
-(() => {
- "use strict";
- // change code below this line
+// change code below this line
- // change code above this line
-})();
+// change code above this line
console.log(a); // should be 6
console.log(b); // should be 8
```
@@ -64,13 +61,6 @@ console.log(b); // should be 8
```js
let a = 8, b = 6;
-(() => {
- "use strict";
- // change code below this line
- [a, b] = [b, a];
- // change code above this line
-})();
-console.log(a); // should be 6
-console.log(b); // should be 8
+[a, b] = [b, a];
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.english.md
index fe204276a8..c92b28a8fa 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.english.md
@@ -26,11 +26,13 @@ Use destructuring assignment within the argument to the function halfstats
should be an object
.
- testString: assert(typeof stats === 'object', 'stats
should be an object
.');
+ testString: assert(typeof stats === 'object');
- text: half(stats)
should be 28.015
- testString: assert(half(stats) === 28.015, 'half(stats)
should be 28.015
');
- - text: Destructuring was used.
- testString: getUserInput => assert(getUserInput('index').match(/\(\s*\{\s*\w+\s*,\s*\w+\s*\}\s*\)/g), 'Destructuring was used.');
+ testString: assert(half(stats) === 28.015);
+ - text: Destructuring should be used.
+ testString: assert(code.replace(/\s/g, '').match(/half=\({\w+,\w+}\)/));
+ - text: Destructured parameter should be used.
+ testString: assert(!code.match(/stats\.max|stats\.min/));
```
@@ -50,17 +52,11 @@ const stats = {
min: -0.75,
average: 35.85
};
-const half = (function() {
- "use strict"; // do not change this line
- // change code below this line
- return function half(stats) {
- // use function argument destructuring
- return (stats.max + stats.min) / 2.0;
- };
- // change code above this line
+// change code below this line
+const half = (stats) => (stats.max + stats.min) / 2.0; // use function argument destructuring
+// change code above this line
-})();
console.log(stats); // should be object
console.log(half(stats)); // should be 28.015
```
@@ -75,6 +71,15 @@ console.log(half(stats)); // should be 28.015
class Book {Notice the syntax we are using to invoke the getter and setter - as if they are not even functions. Getters and setters are important, because they hide internal implementation details. -
constructor(author) {
this._author = author;
}
// getter
get writer(){
return this._author;
}
// setter
set writer(updatedAuthor){
this._author = updatedAuthor;
}
}
const lol = new Book('anonymous');
console.log(lol.writer); // anonymous
lol.writer = 'wut';
console.log(lol.writer); // wut
_
). The practice itself does not make a variable private.
+Note: It is a convention to precede the name of a private variable with an underscore (_
). The practice itself does not make a variable private.
## Instructions
@@ -22,8 +21,7 @@ Getters and setters are important, because they hide internal implementation det
Use class
keyword to create a Thermostat class. The constructor accepts Fahrenheit temperature.
Now create getter
and setter
in the class, to obtain the temperature in Celsius scale.
Remember that C = 5/9 * (F - 32)
and F = C * 9.0 / 5 + 32
, where F is the value of temperature in Fahrenheit scale, and C is the value of the same temperature in Celsius scale
-Note
-When you implement this, you would be tracking the temperature inside the class in one scale - either Fahrenheit or Celsius.
+Note:Thermostat
should be a class
with a defined constructor
method.
- testString: assert(typeof Thermostat === 'function' && typeof Thermostat.constructor === 'function','Thermostat
should be a class
with a defined constructor
method.');
- - text: class
keyword was used.
- testString: getUserInput => assert(getUserInput('index').match(/class/g),'class
keyword was used.');
- - text: Thermostat
can be instantiated.
- testString: assert((() => {const t = new Thermostat(32);return typeof t === 'object' && t.temperature === 0;})(), 'Thermostat
can be instantiated.');
+ testString: assert(typeof Thermostat === 'function' && typeof Thermostat.constructor === 'function');
+ - text: class
keyword should be used.
+ testString: assert(code.match(/class/g));
+ - text: Thermostat
should be able to be instantiated.
+ testString: assert((() => {const t = new Thermostat(32);return typeof t === 'object' && t.temperature === 0;})());
```
@@ -50,14 +48,10 @@ tests:
sum
using the rest parameter in such a way that
```yml
tests:
- text: The result of sum(0,1,2)
should be 3
- testString: assert(sum(0,1,2) === 3, 'The result of sum(0,1,2)
should be 3');
+ testString: assert(sum(0,1,2) === 3);
- text: The result of sum(1,2,3,4)
should be 10
- testString: assert(sum(1,2,3,4) === 10, 'The result of sum(1,2,3,4)
should be 10');
+ testString: assert(sum(1,2,3,4) === 10);
- text: The result of sum(5)
should be 5
- testString: assert(sum(5) === 5, 'The result of sum(5)
should be 5');
+ testString: assert(sum(5) === 5);
- text: The result of sum()
should be 0
- testString: assert(sum() === 0, 'The result of sum()
should be 0');
- - text: The sum
function uses the ...
spread operator on the args
parameter.
- testString: getUserInput => assert(getUserInput('index').match(/function\s+sum\s*\(\s*...args\s*\)\s*{/g), 'The sum
function uses the ...
spread operator on the args
parameter.');
+ testString: assert(sum() === 0);
+ - text: The sum
function should use the ...
rest parameter on the args
parameter.
+ testString: assert(code.replace(/\s/g,'').match(/sum=\(\.\.\.args\)=>/));
```
@@ -43,13 +43,10 @@ tests:
arr1
into another array arr2
usin
```yml
tests:
- - text: arr2
is correct copy of arr1
.
- testString: assert(arr2.every((v, i) => v === arr1[i]), 'arr2
is correct copy of arr1
.');
+ - text: arr2
should be correct copy of arr1
.
+ testString: assert(arr2.every((v, i) => v === arr1[i]));
- text: ...
spread operator was used to duplicate arr1
.
- testString: getUserInput => assert(getUserInput('index').match(/\[\s*...arr1\s*\]/g),'...
spread operator was used to duplicate arr1
.');
- - text: arr2
remains unchanged when arr1
is changed.
- testString: assert((arr1, arr2) => {arr1.push('JUN'); return arr2.length < arr1.length},'arr2
remains unchanged when arr1
is changed.');
+ testString: assert(code.match(/\[\s*...arr1\s*\]/g));
+ - text: arr2
should remain unchanged when arr1
is changed.
+ testString: assert((arr1, arr2) => {arr1.push('JUN'); return arr2.length < arr1.length});
```
@@ -46,10 +46,9 @@ tests:
```js
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2;
-(function() {
- "use strict";
- arr2 = []; // change this line
-})();
+
+arr2 = []; // change this line
+
console.log(arr2);
```
@@ -65,10 +64,7 @@ console.log(arr2);
```js
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2;
-(function() {
- "use strict";
- arr2 = [...arr1]; // change this line
-})();
-console.log(arr2);
+
+arr2 = [...arr1];
```