Aim of the puzzle: Use the .pop() array method to remove an item from the end of an array.
Walk through of solution: Using the .pop()
array method on an array will remove the last item from the array and return it. Because the item is returned, it can be saved to a variable.
In this puzzle, the variable bookShelf
is imported from additional code. This variable contains the following array of strings:
[
'Harry Potter and the Sourcerer\'s Stone',
'Tinker Tailor Soldier Spy',
'Portrait of the Artist as a Young Man',
'Eloquent JavaScript',
'Grace Hopper: Admiral of the Cyber Sea'
]
The second line of code uses .pop()
to remove the last item from the bookShelf
and save it to the variable bookOne
.
To complete the puzzle, add .pop()
to the end of let bookTwo = bookShelf
. Then use console.log()
to print bookTwo
to the console.
Sample code solution:
import { bookShelf } from 'grasshopper.books';
let bookOne = bookShelf.pop();
let bookTwo = bookShelf.pop();
console.log(bookOne);
console.log(bookTwo);
Javascript Concepts: Array Methods, .pop()
, console.log()
, Variable Declarations with Let, Imports
Additional Code (hidden code that runs before the puzzle’s code):
const bookShelf = ['Harry Potter and the Sourcerer\'s Stone', 'Tinker Tailor Soldier Spy', 'Portrait of the Artist as a Young Man', 'Eloquent JavaScript', 'Grace Hopper: Admiral of the Cyber Sea'];