2.0 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			2.0 KiB
		
	
	
	
	
	
	
	
id, title, challengeType
| id | title | challengeType | 
|---|---|---|
| 587d7b8b367417b2b2512b50 | Write Concise Declarative Functions with ES6 | 1 | 
Description
function as follows:
const person = {With ES6, You can remove the
name: "Taylor",
sayHello: function() {
return `Hello! My name is ${this.name}.`;
}
};
function keyword and colon altogether when defining functions in objects. Here's an example of this syntax:
const person = {
name: "Taylor",
sayHello() {
return `Hello! My name is ${this.name}.`;
}
};
Instructions
setGear inside the object bicycle to use the shorthand syntax described above.
Tests
tests:
  - text: Traditional function expression should not be used.
    testString: getUserInput => assert(!getUserInput('index').match(/function/));
  - text: <code>setGear</code> should be a declarative function.
    testString: getUserInput => assert(typeof bicycle.setGear === 'function' && getUserInput('index').match(/setGear\s*\(.+\)\s*\{/));
  - text: <code>bicycle.setGear(48)</code> should change the <code>gear</code> value to 48.
    testString: assert((new bicycle.setGear(48)).gear === 48);
Challenge Seed
// change code below this line
const bicycle = {
  gear: 2,
  setGear: function(newGear) {
    this.gear = newGear;
  }
};
// change code above this line
bicycle.setGear(3);
console.log(bicycle.gear);
Solution
const bicycle = {
  gear: 2,
  setGear(newGear) {
    this.gear = newGear;
  }
};
bicycle.setGear(3);