--- id: 587d7b8b367417b2b2512b50 title: Write Concise Declarative Functions with ES6 localeTitle: Escribir funciones declarativas concisas con ES6 challengeType: 1 --- ## Description
Al definir funciones dentro de objetos en ES5, tenemos que usar la function palabra clave de la siguiente manera:
const person = {
  name: "Taylor",
  sayHello: function() {
    return `Hello! My name is ${this.name}.`;
  }
};
Con ES6, puede eliminar la palabra clave de function y los dos puntos por completo al definir funciones en objetos. Aquí hay un ejemplo de esta sintaxis:
const person = {
  name: "Taylor",
  sayHello() {
    return `Hello! My name is ${this.name}.`;
  }
};
## Instructions
Refactorice la función setGear dentro de la bicycle objeto para usar la sintaxis abreviada descrita anteriormente.
## Tests
```yml tests: - text: No se usó la expresión de función tradicional. testString: 'assert(!getUserInput("index").match(/function/),"Traditional function expression was not used.");' - text: setGear es una función declarativa. testString: 'assert(typeof bicycle.setGear === "function" && getUserInput("index").match(/setGear\s*\(.+\)\s*\{/), "setGear is a declarative function.");' - text: bicycle.setGear (48) cambia el valor de gear a 48. testString: 'assert((new bicycle.setGear(48)).gear === 48, "bicycle.setGear(48) changes the gear value to 48.");' ```
## Challenge Seed
```js // change code below this line const bicycle = { gear: 2, setGear: function(newGear) { "use strict"; this.gear = newGear; } }; // change code above this line bicycle.setGear(3); console.log(bicycle.gear); ```
## Solution
```js // solution required ```