freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-an.../intermediate-algorithm-scri.../arguments-optional.spanish.md

2.3 KiB

id title isRequired challengeType guideUrl videoUrl localeTitle
a97fd23d9b809dac9921074f Arguments Optional true 5 https://spanish.freecodecamp.org/guide/certificates/arguments-optional Argumentos Opcionales

Description

Crear una función que suma dos argumentos juntos. Si solo se proporciona un argumento, entonces devuelva una función que espere un argumento y devuelva la suma. Por ejemplo, addTogether(2, 3) debe devolver 5 y addTogether(2) debe devolver una función. Llamar a esta función devuelta con un solo argumento devolverá la suma: var sumTwoAnd = addTogether(2); sumTwoAnd(3) devuelve 5 . Si cualquiera de los argumentos no es un número válido, devuelva indefinido. Recuerda usar Read-Search-Ask si te atascas. Trate de emparejar el programa. Escribe tu propio código.

Instructions

Tests

tests:
  - text: '<code>addTogether(2, 3)</code> debe devolver 5.'
    testString: 'assert.deepEqual(addTogether(2, 3), 5, "<code>addTogether(2, 3)</code> should return 5.");'
  - text: <code>addTogether(2)(3)</code> debe devolver 5.
    testString: 'assert.deepEqual(addTogether(2)(3), 5, "<code>addTogether(2)(3)</code> should return 5.");'
  - text: '<code>addTogether(&quot;http://bit.ly/IqT6zt&quot;)</code> debe devolver undefined.'
    testString: 'assert.isUndefined(addTogether("http://bit.ly/IqT6zt"), "<code>addTogether("http://bit.ly/IqT6zt")</code> should return undefined.");'
  - text: '<code>addTogether(2, &quot;3&quot;)</code> debe devolver undefined.'
    testString: 'assert.isUndefined(addTogether(2, "3"), "<code>addTogether(2, "3")</code> should return undefined.");'
  - text: '<code>addTogether(2)([3])</code> debe devolver undefined.'
    testString: 'assert.isUndefined(addTogether(2)([3]), "<code>addTogether(2)([3])</code> should return undefined.");'

Challenge Seed

function addTogether() {
  return false;
}

addTogether(2,3);

Solution

// solution required