What's in Store explainer


#1

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 { goods } from 'grasshopper.store';

let shoppingList = [
  'clothing',
  'food',
  'books',
  'toiletries'
];

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

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


Whats in store explainer
Whats in store explainer
listed #2

#3

Continuing the discussion from What's in Store explainer:

Screenshot_2019-01-03-18-06-31-870


#4

This puzzle originally used a variable called departments, but now it uses goods. Be sure to use the variable goods and not a string 'goods'.

–Frankie


#5

What is wrong? Help


#6

The puzzle is being strict here. The starter code uses item as the looping variable instead of element.

Your code will give the correct result, but to pass the puzzle, you can rename element to item by double tapping on the element in let element.

–Frankie