JAVASCRIPT · ОСНОВЫ · LESSON 17

Function with response

Arguments and return · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

Pass the number in.

In the brackets of the function, specify the name of the input number. When calling, give a specific meaning.

function double(number) {
  return number * 2;
}

✦ The function returns a doubled number.

STEP 2

Show me the answer back.

return gives the result to the outside. The function can be called in console.log.

function double(number) {
  return number * 2;
}
console.log(double(3));

✦ 6 will appear.

IN-CLASS PRACTICE

Type the code yourself

Type an example manually. Check the names, brackets and signs.

function add(a, b) {
  return a + b;
}
console.log(add(2, 3));
Open the editor for class work
HOMEWORK

Solve it yourself

Create a multiply function (a, b), which returns the product of a and b. Find the result multiply(3, 4).

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework