Half Off explainer


The aim of this puzzle: Add the updated smallTV object back to the beginning of the televisions array.

Walkthrough of the solution: The code starts by printing the televisions array. Then the 1st element is shifted off and stored in the smallTV variable. The .price property is updated to be 5. We don’t want to set the price to $5, it should be set to half of its original value.

The number 5 should be changed to smallTV.price * 0.5 so that the code says, smallTV.price = smallTV.price * 0.5.

Then the code uses the .unshift() method to add the smallTV to the beginning of the array.

Sample code solution:
(Tap below to reveal)

import { televisions, printTV } from 'grasshopper.store';

let smallTV = televisions.shift();
smallTV.price = smallTV.price * 0.5;
console.log('Updated List:');

JavaScript Concepts: Binary Expression (*), console.log(), .forEach(), import, .shift(), .unshift()