freeCodeCamp Challenge Guide: Passing Values to Functions with Arguments

I’ve struggled to complete the ‘Passing Values to Functions with Arguments’ task. I did look at the forums and watched the video that goes with it too. I then started to delete some of my work to try and work it out step by step, trying to complete each test one at a time.

I did this and I somehow completed all of them with half as much code as I thought I needed.

Code:

function functionWithArgs(a, b) {
console.log(a + b);
}

functionWithArgs(1, 2);

Console:

// running tests
// tests completed
// console output
3
3
16

This completed all of the following tests. However, I can’t work out how that has completed the third or fourth test indicated below.

  • functionWithArgs should be a function.
  • Passed: functionWithArgs(1,2) should output 3.
  • Passed: functionWithArgs(7,9) should output 16.
  • Passed: You should call functionWithArgs with two numbers after you define it.

Hello there,

If you understand correctly, your code passed and you just want to know where test 3 and 4 came from and how you passed them.

In that case, I can explain that these are called edge cases. In the background, fCC does some test to see if your code is bullet proof. So they pass different values to your function and see if it outputs a pre-determined answers. You wont see these tests as fCC does it in the background. But basically, test three runs your function with 7 and 9 as the arguments and check if the answer is 16. If it is, you get a pass. You can learn more about edge cases on Google and checkout hackerrank, which runs your code against many more edge cases.

Edge cases a common part of algorithms, as there is a need to check whether your will consistently produce correct results given different arguments.

Hope this helps!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.