Fix the bug: read the stack trace
So far every lesson asked you to write code from scratch. Real work is more
often the opposite: someone else's code is already there, and it's broken. The
skill that matters is reading the error the runtime hands you - it almost
always names the exact problem, if you read it instead of guessing.
The code below throws as soon as you press Run - it isn't waiting for a test
to fail it, the bug crashes it immediately. TypeError: Cannot read properties of undefined (reading '...') means you tried to use a property on something
that turned out to be undefined - and the property name in the message is
usually the clue pointing at a typo one line up.
Your task: run the code, read the error, and fix the bug in formatPrice
so it returns the price formatted to two decimal places.
You'll practice:
Reading a thrown error and stack trace instead of guessing
Tracing a TypeError back to the typo that caused it
Show a hint
Show solution
Previous Next