# 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 / 2` so that the code says, `smallTV.price = smallTV.price / 2`.

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

televisions.forEach(printTV);
let smallTV = televisions.shift();
smallTV.price = smallTV.price / 2;
televisions.unshift(smallTV);
console.log('Updated List:');
televisions.forEach(printTV);
``````

JavaScript Concepts: Binary Expression (*), `console.log()`, `.forEach()`, `import`, `.shift()`, `.unshift()`
Additional Code (hidden code that runs before the puzzle’s code):

``````let televisions = [32, 40, 50, 55, 60].map(i => ({
size: i + `"`,
price: (i ** 1.5).toFixed(2)
}));

const printTV = tv => {
console.log(tv.size + ' for \$' + tv.price)
};

``````

okaaaay. I only have the option to divide by 2, not multiply by 0.5. it’s not allowing me to advance

I’ve updated the explainer to use `/ 2`. This puzzle used to use `* 0.5`, but some phones use the phone number pad which doesn’t include a decimal point.

If you’re still unable to advance, there may be something else to change. If you post a screenshot of your code I can take a look.

–Frankie

It’s not allow me to pass. I did it on my iPhone.

Hey there,

You’re dividing the `smallTV.price` by 2, but you aren’t doing anything with the result, so `smallTV.price` isn’t changing at all.

Change that line to `smallTV.price = smallTV.price / 2`. This will divide the price by 2, and then assign the result back to `smallTV.price`.

Hope this helps!
Ben

I dont understand this… why do I want to update the price when if I just run the code as is I get a 32" TV for \$5 instead of manually upping the price to \$90.51?

Sorry, I’m just trolling. I thought it was funny

2 Likes

Hey @Grasshopper_Ben and the others, Im kinda confused here. Im using my laptop.

Can anyone have a look at it.

Thanks,

Farhaan Qaisar Usmani