Slice of Pie explainer


#1

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);

console.log(plate);

JavaScript Concepts: .slice(), Array Methods, Arrays, Import Statements, Variable Declarations with Let, Console, Strings