Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244bd.md
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.1 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
56533eb9ac21ba0edf2244bd Passing Values to Functions with Arguments 1 18254 passing-values-to-functions-with-arguments

--description--

Parameters are variables that act as placeholders for the values that are to be input to a function when it is called. When a function is defined, it is typically defined along with one or more parameters. The actual values that are input (or "passed") into a function when it is called are known as arguments.

Here is a function with two parameters, param1 and param2:

function testFun(param1, param2) {
  console.log(param1, param2);
}

Then we can call testFun like this: testFun("Hello", "World");. We have passed two string arguments, Hello and World. Inside the function, param1 will equal the string Hello and param2 will equal the string World. Note that you could call testFun again with different arguments and the parameters would take on the value of the new arguments.

--instructions--

  1. Create a function called functionWithArgs that accepts two arguments and outputs their sum to the dev console.
  2. Call the function with two numbers as arguments.

--before-each--

var logOutput;

--hints--

functionWithArgs should be a function.

assert(typeof functionWithArgs === 'function');

functionWithArgs(1,2) should output 3.

console.log = function (message) {
  logOutput = message
};
functionWithArgs(1, 2);
assert(logOutput == 3);

functionWithArgs(7,9) should output 16.

console.log = function (message) {
  logOutput = message
};
functionWithArgs(7, 9);
assert(logOutput == 16);

You should call functionWithArgs with two numbers after you define it.

assert(
  /functionWithArgs\([-+]?\d*\.?\d*,[-+]?\d*\.?\d*\)/.test(
    __helpers.removeJSComments(code).replace(/\s/g, '')
  )
);

--seed--

--seed-contents--


--solutions--

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