Clear names
JavaScript · Unit 19: Clean code
- Full plan
- JavaScript
- 9 exercises
Changing a name doesn't change what the program does: it changes what the person reading it understands. And that person makes decisions.
The two lines below compute the same thing. Only one tells you what you're looking at.
const t = 180 + 50;
const totalWithShipping = 180 + 50;
console.log(t, totalWithShipping);Prints
230 230
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. Predict the output
What does this code print?
2. Multiple choice
Which name would tell the truth about what
xholds?3. Find the bug
taxshould hand back only the 10% that gets added to the price, so the 200 purchase has to print 220. Which line has the error?4. Complete the code
Fill in the declaration of
laps, which counts how many times the loop went around.5. Predict the output
What does this code print?
6. Find the bug
In one class 9 out of 10 passed and in another 15 out of 20, so it should print 90 and 75. Which line has the error?
7. Complete the code
What you charge includes the tax and the shipping. Fill in the line.
8. Put the lines in order
Put
average(scores)in order: the sum of the scores divided by how many there are.9. Predict the output
What does this code print?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.