Parameters
JavaScript · Unit 4: Functions
- Full plan
- JavaScript
- 10 exercises
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. Complete the code
Fill in the call to work out the area of a 5 by 2 rectangle.
2. Multiple choice
In
function total(price, quantity) {, what arepriceandquantity?3. Predict the output
What does this code print?
4. Predict the output
What does this code print?
5. Complete the code
Fill in the parameters so a 200 check is split among 4 people.
6. Predict the output
What does this code print?
7. Find the bug
This program should print what 3 shirts at 20 cost. Which line has the error?
8. Predict the output
What does this code print?
9. Find the case that fails
fits(width, space)should givetrueif a bookshelf fits in the space, including when it measures exactly the same. Which call makes it fail?10. Put the lines in order
Put in order the function that splits a 200 check among 4 people.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.