Project: grocery list
JavaScript · Unit 5: Arrays
- Full plan
- JavaScript
- Project
- 8 exercises
Your grocery list is two arrays: items[i] and prices[i] talk about the same product, because the same index ties them together.
To read them together, you walk through with an index for.
const items = ["bread", "milk"];
const prices = [3, 4];
const n = prices.length;
for (let i = 0; i < n; i++) {
console.log(items[i], prices[i]);
}Prints
bread 3 milk 4
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Complete the code
Complete it to print the items that cost less than 10.
2. Predict the output
You are taking 2 breads and 3 milks. What does it print?
3. Find the bug
This program should print the three prices. Which line has the error?
4. Write the code
Write
total(prices, counts), which returns what you pay if you takecounts[i]of each product atprices[i]each.5. Multiple choice
What does
subshold when this code is done?6. Write the code
Write
priciest(items, prices), which returns the name of the most expensive product. The arrays never come in empty.7. Complete the code
Complete it to keep the prices under 10.
8. Predict the output
These are the prices on your list. What does it print?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.