Files
.github
api-server
client
config
curriculum
challenges
_meta
arabic
chinese
english
portuguese
russian
spanish
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
debugging
es6
compare-scopes-of-the-var-and-let-keywords.spanish.md
create-an-export-fallback-with-export-default.spanish.md
create-strings-using-template-literals.spanish.md
declare-a-read-only-variable-with-the-const-keyword.spanish.md
explore-differences-between-the-var-and-let-keywords.spanish.md
import-a-default-export.spanish.md
mutate-an-array-declared-with-const.spanish.md
prevent-object-mutation.spanish.md
set-default-parameters-for-your-functions.spanish.md
understand-the-differences-between-import-and-require.spanish.md
use--to-import-everything-from-a-file.spanish.md
use-arrow-functions-to-write-concise-anonymous-functions.spanish.md
use-class-syntax-to-define-a-constructor-function.spanish.md
use-destructuring-assignment-to-assign-variables-from-arrays.spanish.md
use-destructuring-assignment-to-assign-variables-from-nested-objects.spanish.md
use-destructuring-assignment-to-assign-variables-from-objects.spanish.md
use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.spanish.md
use-destructuring-assignment-with-the-rest-operator-to-reassign-array-elements.spanish.md
use-export-to-reuse-a-code-block.spanish.md
use-getters-and-setters-to-control-access-to-an-object.spanish.md
use-the-rest-operator-with-function-parameters.spanish.md
use-the-spread-operator-to-evaluate-arrays-in-place.spanish.md
write-arrow-functions-with-parameters.spanish.md
write-concise-declarative-functions-with-es6.spanish.md
write-concise-object-literal-declarations-using-simple-fields.spanish.md
write-higher-order-arrow-functions.spanish.md
functional-programming
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
03-front-end-libraries
04-data-visualization
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
formattingConversion
math-challenges
requiresTests
schema
test
.babelrc
.editorconfig
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.md
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.js
gulpfile.js
index.js
lib.js
md-translation.js
package-entry.js
package-lock.json
package.json
utils.js
docs
guide
mock-guide
tools
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.french.md
README.italian.md
README.md
docker-compose-shared.yml
docker-compose.yml
lerna.json
netlify.toml
package-lock.json
package.json
sample.env
freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions.spanish.md

61 lines
2.3 KiB
Markdown
Raw Normal View History

2018-10-08 13:34:43 -04:00
---
id: 587d7b88367417b2b2512b46
title: Set Default Parameters for Your Functions
challengeType: 1
2018-10-10 16:20:40 -04:00
videoUrl: ''
localeTitle: Establecer parámetros predeterminados para sus funciones
2018-10-08 13:34:43 -04:00
---
## Description
2018-10-10 16:20:40 -04:00
<section id="description"> Para ayudarnos a crear funciones más flexibles, ES6 introduce <dfn>parámetros predeterminados</dfn> para las funciones. Echa un vistazo a este código: <blockquote> función de saludo (nombre = &quot;Anónimo&quot;) { <br> devuelve &quot;Hola&quot; + nombre; <br> } <br> console.log (saludo (&quot;John&quot;)); // Hola John <br> console.log (saludo ()); // Hola Anónimo </blockquote> El parámetro predeterminado se activa cuando el argumento no está especificado (no está definido). Como puede ver en el ejemplo anterior, el <code>name</code> del parámetro recibirá su valor predeterminado <code>&quot;Anonymous&quot;</code> cuando no proporcione un valor para el parámetro. Puede agregar valores predeterminados para tantos parámetros como desee. </section>
2018-10-08 13:34:43 -04:00
## Instructions
2018-10-10 16:20:40 -04:00
<section id="instructions"> Modifique el <code>increment</code> la función agregando parámetros predeterminados para que agregue 1 al <code>number</code> si no se especifica el <code>value</code> . </section>
2018-10-08 13:34:43 -04:00
## Tests
<section id='tests'>
```yml
tests:
2018-10-10 16:20:40 -04:00
- text: 'El resultado del <code>increment(5, 2)</code> debe ser <code>7</code> .'
2018-10-08 13:34:43 -04:00
testString: 'assert(increment(5, 2) === 7, "The result of <code>increment(5, 2)</code> should be <code>7</code>.");'
- text: El resultado del <code>increment(5)</code> debe ser <code>6</code> .
testString: 'assert(increment(5) === 6, "The result of <code>increment(5)</code> should be <code>6</code>.");'
- text: se usó el parámetro por defecto <code>1</code> para el <code>value</code> .
testString: 'getUserInput => assert(getUserInput("index").match(/value\s*=\s*1/g), "default parameter <code>1</code> was used for <code>value</code>.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
const increment = (function() {
"use strict";
return function increment(number, value) {
return number + value;
};
})();
console.log(increment(5, 2)); // returns 7
console.log(increment(5)); // returns 6
2018-10-10 16:20:40 -04:00
2018-10-08 13:34:43 -04:00
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>