What's in Store explainer


The aim of this puzzle: Check if each item in the shopping list is in the departments array.

Walkthrough of the solution: The departments array is imported from 'grasshopper.store'. Then shoppingList array is created. The last part of the code is the For Loop.

The loop goes through each element of the shoppingList. It logs some output for each item. Take a look at what it’s logging: element + ': ' + departments.includes('clothing')

1st is the element which is just the current item in the shoppingList. Then a ': ' which is just a string used to organize the output. The last part is departments.includes('clothing'). That will check if the string 'clothing' is an element of the departments array. Instead of searching for 'clothing' each time, it should check for the current item. Change this string to the element variable.

Sample code solution:
(Tap below to reveal)

import { departments } from 'grasshopper.store';

let shoppingList = [

for (let element of shoppingList) {
  console.log(element + ': ' + departments.includes(element));

JavaScript Concepts: Binary Expression (+ concatenation), Code Block (for loop), Data Structures (array), import, .includes()