Skip to the content

Parameters

JavaScript · Unit 4: Functions

A parameter is a variable the function receives when you call it. If there are several, commas separate them.

The value you pass in the call is called an argument.

function area(base, height) {
  return base * height;
}

console.log(area(4, 3));

Prints

12

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Complete the code

    Fill in the call to work out the area of a 5 by 2 rectangle.

  2. 2. Multiple choice

    In function total(price, quantity) {, what are price and quantity?

  3. 3. Predict the output

    What does this code print?

  4. 4. Predict the output

    What does this code print?

  5. 5. Complete the code

    Fill in the parameters so a 200 check is split among 4 people.

  6. 6. Predict the output

    What does this code print?

  7. 7. Find the bug

    This program should print what 3 shirts at 20 cost. Which line has the error?

  8. 8. Predict the output

    What does this code print?

  9. 9. Find the case that fails

    fits(width, space) should give true if a bookshelf fits in the space, including when it measures exactly the same. Which call makes it fail?

  10. 10. Put the lines in order

    Put in order the function that splits a 200 check among 4 people.

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →