...

/

Solution Review: Purchase Items

Solution Review: Purchase Items

Let’s take a look at the solution to the "Purchase Items" problem.

We'll cover the following...

Task 1

Let’s dive into the solution to task 1.

Solution

const purchaseItems = function(essential1, essential2, ...optionals) {
console.log(essential1 + ', ' + essential2 + ', ' + optionals.join(', '));
};
purchaseItems('bread', 'milk');
purchaseItems('bread', 'milk', 'jelly');
const mustHaves = ['bread', 'milk'];
const andAlso = ['eggs', 'donuts', 'tea'];
//call purchaseItems so it prints bread, milk, eggs, donuts, tea
purchaseItems(...mustHaves, ...andAlso);

Explanation

The first task requires us to add the third function call so that output is bread, milk, eggs, donuts, tea.

  • We have two ...

Access this course and 1400+ top-rated courses and projects.