Slice of Pie explainer

The aim of this puzzle: Use the .slice() array method to select and copy a portion of an array.

Walkthrough of the solution: The .slice() array method is used to copy a portion of an array. It takes 2 arguments: an array index where to start copying, and an array index where to stop. The element at the stop index is not included.

In this puzzle, the pie array is imported from additional code. It contains a list of strings like 'big slice', 'small slice', and 'medium slice'.

The plate variable is where we’ll store the elements we copy from pie. To copy these elements, add .slice() to pie and give it 2 arguments. When plate is logged to the console, the copied elements will be printed out.

Sample code solution:
(Tap below to reveal)

import { pie } from 'grasshopper.bakery';

let plate = pie.slice(2,3);


JavaScript Concepts: .slice(), Array Methods, Arrays, Import Statements, Variable Declarations with Let, Console, Strings
Additional Code (hidden code that runs before the puzzle’s code):

const pie = ['big slice', 'little slice', 'huge slice', 'tiny slice', 'medium slice', 'home slice'];
1 Like

hi I dont understand why if I’m putting onto the array: (0,1)
it just calls the first item