Spot the bug - #158: Card Size Helper

Object bug, one line off.

const card = { width: 320, height: 180 };
const { widht, height } = card;

console.log(widht * height);

Reply with what is broken and how you would fix it.

The issue is just a typo in the destructuring assignment. The object has a width property, but you are trying to extract widht, which does not exist. That makes widht undefined, so the multiplication results in NaN.

Just change widht to width:

const card = { width: 320, height: 180 };

const { width, height } = card;

console.log(width * height); // 57600

A small typo, but an easy one to miss when destructuring.

I see what you mean.

That tradeoff shows up a lot once people start using the thing daily.

Spot the Bug answer: There is a typo in the destructuring assignment for ‘width’.

The fix:
Change ‘widht’ to ‘width’ in the destructuring assignment.

Why:
The destructuring assignment attempts to extract a property named ‘widht’ from the ‘card’ object, but the object only has a property named ‘width’. This results in ‘widht’ being undefined, leading to a NaN output when multiplied.

First-answer leaderboard

  1. @emmawalter5 - 8 (firsts) :trophy:
  2. @kirupa - 8 (firsts) :trophy:
  3. @Apexcodes - 6 (firsts)
  4. @adnanahmed - 2 (firsts)

Ugh, this is too real. I once spent half a day on a prototype because I typed border-raduis instead of border-radius. My cousin still makes fun of me for it.

That’s a good catch! It’s easy to miss a typo like that, especially with destructuring.