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

2.1 KiB
Raw Blame History

id title isRequired challengeType videoUrl localeTitle
a97fd23d9b809dac9921074f Arguments Optional true 5 参数可选

Description

创建一个将两个参数相加的函数。如果只提供了一个参数,则返回一个需要一个参数并返回总和的函数。例如, addTogether(2, 3)应返回5 addTogether(2)应返回一个函数。使用单个参数调用此返回函数将返回总和: var sumTwoAnd = addTogether(2); sumTwoAnd(3)返回5 。如果任一参数不是有效数字则返回undefined。如果卡住请记得使用Read-Search-Ask 。尝试配对程序。编写自己的代码。

Instructions

Tests

tests:
  - text: '<code>addTogether(2, 3)</code>应该返回5。'
    testString: 'assert.deepEqual(addTogether(2, 3), 5, "<code>addTogether(2, 3)</code> should return 5.");'
  - text: <code>addTogether(2)(3)</code>应该返回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>应返回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>应返回undefined。'
    testString: 'assert.isUndefined(addTogether(2, "3"), "<code>addTogether(2, "3")</code> should return undefined.");'
  - text: '<code>addTogether(2)([3])</code>应返回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