Spot the bug - #113: 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.

What is widht? Misspelling alert!

Guess is logged, @kirupa. Answer goes up later today, no spoilers from me.

Spot the Bug answer: A typo exists in the destructuring assignment for the ‘width’ property.

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 (Not a Number) result when multiplied by ‘height’.


Got it: @kirupa :trophy:

First-answer leaderboard

  1. @kirupa - 4 (firsts) :trophy:
  2. @adnanahmed - 1 (first)
  3. @emmawalter5 - 1 (first)

lol “widht” is such a classic. I’ve definitely shipped stuff like that before.

It’s always the tiny things that get you.