Project: An Expedition Supply Checker

Over this course, you’ve collected a set of loop patterns. You counted the snacks on a shared camping list, selected everything that wasn’t snacks, added up a week of walks, and stopped at the first song that started with "M". Each time, a lesson showed you which pattern to use.

In this project, that choice is yours. You’ll get a short brief for an expedition supply checker with four small tasks. For each task, you’ll decide which pattern it needs and what it returns for an empty list before you write any code. Then you’ll build the checker in two on-site exercises and finish by explaining your code in a mentor review.

Meet the Expedition and Its Supplies

Say you’re helping a small group plan a four-day hiking trip in the mountains. Everyone has packed their share of the gear into crates, and you’ve offered to check the supplies before the van leaves. Two questions keep coming up, one about the names written on the crates and one about how much everything weighs.

Here are the supplies as two lists. Create supplies.js in your course folder and add them.

Language: JavaScript Filename: supplies.js
const names = [
  "headlamp", "water filter", "stove", "tent",
  "first aid kit", "water filter", "rope", "sleeping bag"
];
const weights = [1, 1, 3, 9, 2, 1, 4, 2];

console.log(names.length);
console.log(weights.length);
console.log(names[3]);
console.log(weights[3]);

Before you run the code, predict the four lines of output. Remember that positions count from 0.

Language: Shell
$ node supplies.js
8
8
tent
9

The two lists line up by position. The supply at index 3 is the tent, and the number at index 3 is its weight: 9 kilograms. Keeping them apart is a little clumsy, and a later course shows you how to keep a name and its weight together. For now, each task works on one list only, either the names or the weights.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.