Slice of Pizza 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 pizza 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 pizza. To copy these elements, add .slice() to pizza 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 { pizza } from 'grasshopper.pizzeria';

let plate = pizza.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 pizza = ['big slice', 'little slice', 'huge slice', 'tiny slice', 'medium slice', 'home slice'];
1 Like